From 2ac21426af44248f6c58ab2cb77bfff7e8a06df1 Mon Sep 17 00:00:00 2001 From: Tom Duijf Date: Thu, 23 Jun 2016 21:19:17 +0200 Subject: [PATCH 1/2] use already available home variable for user's ssh-key configuration --- users/init.sls | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/users/init.sls b/users/init.sls index 444053f..319e93b 100644 --- a/users/init.sls +++ b/users/init.sls @@ -38,7 +38,8 @@ include: {%- if user == None -%} {%- set user = {} -%} {%- 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'] %} {%- set user_group = user.prime_group.name -%} @@ -79,7 +80,7 @@ users_{{ name }}_user: user.present: - name: {{ name }} - 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 -%} - uid: {{ user['uid'] }} {% endif -%} @@ -149,7 +150,7 @@ users_{{ name }}_user: 'ssh_config' in user %} user_keydir_{{ name }}: file.directory: - - name: {{ user.get('home', '/home/{0}'.format(name)) }}/.ssh + - name: {{ home }}/.ssh - user: {{ name }} - group: {{ user_group }} - makedirs: True @@ -166,8 +167,7 @@ user_keydir_{{ name }}: {% set key_type = 'id_' + user.get('ssh_key_type', 'rsa') %} users_user_{{ name }}_private_key: file.managed: - - name: {{ user.get('home', - '/home/{0}'.format(name)) }}/.ssh/{{ key_type }} + - name: {{ home }}/.ssh/{{ key_type }} - user: {{ name }} - group: {{ user_group }} - mode: 600 @@ -180,8 +180,7 @@ users_user_{{ name }}_private_key: {% endfor %} users_user_{{ name }}_public_key: file.managed: - - name: {{ user.get('home', - '/home/{0}'.format(name)) }}/.ssh/{{ key_type }}.pub + - name: {{ home }}/.ssh/{{ key_type }}.pub - user: {{ name }} - group: {{ user_group }} - mode: 644 @@ -230,8 +229,7 @@ users_ssh_auth_{{ name }}_{{ loop.index0 }}: {% for key_name, pillar_name in user['ssh_keys_pillar'].items() %} user_ssh_keys_files_{{ name }}_{{ key_name }}_private_key: file.managed: - - name: {{ user.get('home', - '/home/{0}'.format(name)) }}/.ssh/{{ key_name }} + - name: {{ home }}/.ssh/{{ key_name }} - user: {{ name }} - group: {{ user_group }} - mode: 600 @@ -244,8 +242,7 @@ user_ssh_keys_files_{{ name }}_{{ key_name }}_private_key: {% endfor %} user_ssh_keys_files_{{ name }}_{{ key_name }}_public_key: file.managed: - - name: {{ user.get('home', - '/home/{0}'.format(name)) }}/.ssh/{{ key_name }}.pub + - name: {{ home }}/.ssh/{{ key_name }}.pub - user: {{ name }} - group: {{ user_group }} - mode: 644 From 5cd73534add249db0898533381a627b3235734ec Mon Sep 17 00:00:00 2001 From: Tom Duijf Date: Thu, 23 Jun 2016 21:43:01 +0200 Subject: [PATCH 2/2] Updated remaining files to retain home dir existing user --- users/bashrc.sls | 3 ++- users/profile.sls | 3 ++- users/user_files.sls | 3 ++- users/vimrc.sls | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/users/bashrc.sls b/users/bashrc.sls index fc268f4..4d4ca4d 100644 --- a/users/bashrc.sls +++ b/users/bashrc.sls @@ -3,10 +3,11 @@ include: - users {% for name, user in pillar.get('users', {}).items() if user.absent is not defined or not user.absent %} +{%- set current = salt.user.info(name) -%} {%- if user == None -%} {%- set user = {} -%} {%- endif -%} -{%- set home = user.get('home', "/home/%s" % name) -%} +{%- set home = user.get('home', current.get('home', "/home/%s" % name)) -%} {%- set manage = user.get('manage_bashrc', False) -%} {%- if 'prime_group' in user and 'name' in user['prime_group'] %} {%- set user_group = user.prime_group.name -%} diff --git a/users/profile.sls b/users/profile.sls index b62c096..55ac8e2 100644 --- a/users/profile.sls +++ b/users/profile.sls @@ -3,10 +3,11 @@ include: - users {% for name, user in pillar.get('users', {}).items() if user.absent is not defined or not user.absent %} +{%- set current = salt.user.info(name) -%} {%- if user == None -%} {%- set user = {} -%} {%- endif -%} -{%- set home = user.get('home', "/home/%s" % name) -%} +{%- set home = user.get('home', current.get('home', "/home/%s" % name)) -%} {%- set manage = user.get('manage_profile', False) -%} {%- if 'prime_group' in user and 'name' in user['prime_group'] %} {%- set user_group = user.prime_group.name -%} diff --git a/users/user_files.sls b/users/user_files.sls index 95c1281..461628b 100644 --- a/users/user_files.sls +++ b/users/user_files.sls @@ -5,9 +5,10 @@ include: {% set userfile_dirs = salt['cp.list_master_dirs'](prefix='users/files/user/') -%} {%- for username, user in salt['pillar.get']('users', {}).items() if (user.absent is not defined or not user.absent) -%} +{%- set current = salt.user.info(username) -%} {%- set user_files = salt['pillar.get'](('users:' ~ username ~ ':user_files'), {'enabled': False}) -%} {%- set user_group = salt['pillar.get'](('users:' ~ username ~ ':prime_group:name'), username) -%} -{%- set user_home = salt['pillar.get'](('users:' ~ username ~ ':home'), '/home/' ~ username ) -%} +{%- set user_home = salt['pillar.get'](('users:' ~ username ~ ':home'), current.get('home', '/home/' ~ username )) -%} {%- if user_files.enabled -%} {%- if user_files.source is defined -%} diff --git a/users/vimrc.sls b/users/vimrc.sls index e678bb6..5404738 100644 --- a/users/vimrc.sls +++ b/users/vimrc.sls @@ -4,10 +4,11 @@ include: - vim {% for name, user in pillar.get('users', {}).items() if user.absent is not defined or not user.absent %} +{%- set current = salt.user.info(name) -%} {%- if user == None -%} {%- set user = {} -%} {%- endif -%} -{%- set home = user.get('home', "/home/%s" % name) -%} +{%- set home = user.get('home', current.get('home', "/home/%s" % name)) -%} {%- set manage = user.get('manage_vimrc', False) -%} {%- if 'prime_group' in user and 'name' in user['prime_group'] %} {%- set user_group = user.prime_group.name -%}