use already available home variable for user's ssh-key configuration

This commit is contained in:
Tom Duijf 2016-06-23 21:19:17 +02:00
parent ebc81c806b
commit 2ac21426af

View File

@ -38,7 +38,8 @@ include:
{%- if user == None -%} {%- if user == None -%}
{%- set user = {} -%} {%- set user = {} -%}
{%- endif -%} {%- endif -%}
{%- set home = user.get('home', "/home/%s" % name) -%} {%- set current = salt.user.info(name) -%}
{%- set home = user.get('home', current.get('home', "/home/%s" % name)) -%}
{%- if 'prime_group' in user and 'name' in user['prime_group'] %} {%- if 'prime_group' in user and 'name' in user['prime_group'] %}
{%- set user_group = user.prime_group.name -%} {%- set user_group = user.prime_group.name -%}
@ -79,7 +80,7 @@ users_{{ name }}_user:
user.present: user.present:
- name: {{ name }} - name: {{ name }}
- home: {{ home }} - home: {{ home }}
- shell: {{ user.get('shell', users.get('shell', '/bin/bash')) }} - shell: {{ user.get('shell', current.get('shell', users.get('shell', '/bin/bash'))) }}
{% if 'uid' in user -%} {% if 'uid' in user -%}
- uid: {{ user['uid'] }} - uid: {{ user['uid'] }}
{% endif -%} {% endif -%}
@ -149,7 +150,7 @@ users_{{ name }}_user:
'ssh_config' in user %} 'ssh_config' in user %}
user_keydir_{{ name }}: user_keydir_{{ name }}:
file.directory: file.directory:
- name: {{ user.get('home', '/home/{0}'.format(name)) }}/.ssh - name: {{ home }}/.ssh
- user: {{ name }} - user: {{ name }}
- group: {{ user_group }} - group: {{ user_group }}
- makedirs: True - makedirs: True
@ -166,8 +167,7 @@ user_keydir_{{ name }}:
{% set key_type = 'id_' + user.get('ssh_key_type', 'rsa') %} {% set key_type = 'id_' + user.get('ssh_key_type', 'rsa') %}
users_user_{{ name }}_private_key: users_user_{{ name }}_private_key:
file.managed: file.managed:
- name: {{ user.get('home', - name: {{ home }}/.ssh/{{ key_type }}
'/home/{0}'.format(name)) }}/.ssh/{{ key_type }}
- user: {{ name }} - user: {{ name }}
- group: {{ user_group }} - group: {{ user_group }}
- mode: 600 - mode: 600
@ -180,8 +180,7 @@ users_user_{{ name }}_private_key:
{% endfor %} {% endfor %}
users_user_{{ name }}_public_key: users_user_{{ name }}_public_key:
file.managed: file.managed:
- name: {{ user.get('home', - name: {{ home }}/.ssh/{{ key_type }}.pub
'/home/{0}'.format(name)) }}/.ssh/{{ key_type }}.pub
- user: {{ name }} - user: {{ name }}
- group: {{ user_group }} - group: {{ user_group }}
- mode: 644 - mode: 644
@ -230,8 +229,7 @@ users_ssh_auth_{{ name }}_{{ loop.index0 }}:
{% for key_name, pillar_name in user['ssh_keys_pillar'].items() %} {% for key_name, pillar_name in user['ssh_keys_pillar'].items() %}
user_ssh_keys_files_{{ name }}_{{ key_name }}_private_key: user_ssh_keys_files_{{ name }}_{{ key_name }}_private_key:
file.managed: file.managed:
- name: {{ user.get('home', - name: {{ home }}/.ssh/{{ key_name }}
'/home/{0}'.format(name)) }}/.ssh/{{ key_name }}
- user: {{ name }} - user: {{ name }}
- group: {{ user_group }} - group: {{ user_group }}
- mode: 600 - mode: 600
@ -244,8 +242,7 @@ user_ssh_keys_files_{{ name }}_{{ key_name }}_private_key:
{% endfor %} {% endfor %}
user_ssh_keys_files_{{ name }}_{{ key_name }}_public_key: user_ssh_keys_files_{{ name }}_{{ key_name }}_public_key:
file.managed: file.managed:
- name: {{ user.get('home', - name: {{ home }}/.ssh/{{ key_name }}.pub
'/home/{0}'.format(name)) }}/.ssh/{{ key_name }}.pub
- user: {{ name }} - user: {{ name }}
- group: {{ user_group }} - group: {{ user_group }}
- mode: 644 - mode: 644