Browse Source

Merge pull request #121 from tomduijf/master

Keep existing user's home and shell unless explicitly defined
lookup-fix-3
Wolodja Wentland 8 years ago
parent
commit
4caa3f8d4b
5 changed files with 16 additions and 15 deletions
  1. +2
    -1
      users/bashrc.sls
  2. +8
    -11
      users/init.sls
  3. +2
    -1
      users/profile.sls
  4. +2
    -1
      users/user_files.sls
  5. +2
    -1
      users/vimrc.sls

+ 2
- 1
users/bashrc.sls View File

- users - users


{% for name, user in pillar.get('users', {}).items() if user.absent is not defined or not user.absent %} {% 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 -%} {%- if user == None -%}
{%- set user = {} -%} {%- set user = {} -%}
{%- endif -%} {%- 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) -%} {%- set manage = user.get('manage_bashrc', False) -%}
{%- 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 -%}

+ 8
- 11
users/init.sls View File

{%- 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 -%}
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 -%}
'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
{% 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',
'/home/{0}'.format(name)) }}/.ssh/{{ key_type }}
- name: {{ home }}/.ssh/{{ key_type }}
- user: {{ name }} - user: {{ name }}
- group: {{ user_group }} - group: {{ user_group }}
- mode: 600 - mode: 600
{% endfor %} {% endfor %}
users_user_{{ name }}_public_key: users_user_{{ name }}_public_key:
file.managed: file.managed:
- name: {{ user.get('home',
'/home/{0}'.format(name)) }}/.ssh/{{ key_type }}.pub
- name: {{ home }}/.ssh/{{ key_type }}.pub
- user: {{ name }} - user: {{ name }}
- group: {{ user_group }} - group: {{ user_group }}
- mode: 644 - mode: 644
{% 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',
'/home/{0}'.format(name)) }}/.ssh/{{ key_name }}
- name: {{ home }}/.ssh/{{ key_name }}
- user: {{ name }} - user: {{ name }}
- group: {{ user_group }} - group: {{ user_group }}
- mode: 600 - mode: 600
{% 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',
'/home/{0}'.format(name)) }}/.ssh/{{ key_name }}.pub
- name: {{ home }}/.ssh/{{ key_name }}.pub
- user: {{ name }} - user: {{ name }}
- group: {{ user_group }} - group: {{ user_group }}
- mode: 644 - mode: 644

+ 2
- 1
users/profile.sls View File

- users - users


{% for name, user in pillar.get('users', {}).items() if user.absent is not defined or not user.absent %} {% 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 -%} {%- if user == None -%}
{%- set user = {} -%} {%- set user = {} -%}
{%- endif -%} {%- 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) -%} {%- set manage = user.get('manage_profile', False) -%}
{%- 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 -%}

+ 2
- 1
users/user_files.sls View File



{% set userfile_dirs = salt['cp.list_master_dirs'](prefix='users/files/user/') -%} {% 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) -%} {%- 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_files = salt['pillar.get'](('users:' ~ username ~ ':user_files'), {'enabled': False}) -%}
{%- set user_group = salt['pillar.get'](('users:' ~ username ~ ':prime_group:name'), username) -%} {%- 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.enabled -%}


{%- if user_files.source is defined -%} {%- if user_files.source is defined -%}

+ 2
- 1
users/vimrc.sls View File

- vim - vim


{% for name, user in pillar.get('users', {}).items() if user.absent is not defined or not user.absent %} {% 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 -%} {%- if user == None -%}
{%- set user = {} -%} {%- set user = {} -%}
{%- endif -%} {%- 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) -%} {%- set manage = user.get('manage_vimrc', False) -%}
{%- 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 -%}

Loading…
Cancel
Save