possibility to define alternate user`s prime group

This commit is contained in:
tiger-seo 2014-01-13 17:23:46 +02:00
parent 260388cd20
commit 5ce8d7d2c5

View File

@ -2,10 +2,16 @@ include:
- users.sudo - users.sudo
{% for name, user in pillar.get('users', {}).items() %} {% for name, user in pillar.get('users', {}).items() %}
{% 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', "/home/%s" % name) -%}
{%- if 'prime_group' in user and 'name' in user['prime_group'] %}
{%- set user_group = user.prime_group.name -%}
{%- else -%}
{%- set user_group = name -%}
{%- endif %}
{% for group in user.get('groups', []) %} {% for group in user.get('groups', []) %}
{{ group }}_group: {{ group }}_group:
@ -18,58 +24,64 @@ include:
file.directory: file.directory:
- name: {{ home }} - name: {{ home }}
- user: {{ name }} - user: {{ name }}
- group: {{ name }} - group: {{ user_group }}
- mode: 0755 - mode: 0755
- require: - require:
- user: {{ name }} - user: {{ name }}
- group: {{ name }} - group: {{ user_group }}
group.present: group.present:
- name: {{ name }} - name: {{ user_group }}
{% if 'uid' in user -%} {%- if 'prime_group' in user and 'gid' in user['prime_group'] %}
- gid: {{ user['prime_group']['gid'] }}
{%- elif 'uid' in user %}
- gid: {{ user['uid'] }} - gid: {{ user['uid'] }}
{% endif %} {%- endif %}
user.present: user.present:
- name: {{ name }} - name: {{ name }}
- home: {{ home }} - home: {{ home }}
- shell: {{ user.get('shell', '/bin/bash') }} - shell: {{ user.get('shell', '/bin/bash') }}
{% if 'uid' in user -%} {% if 'uid' in user -%}
- uid: {{ user['uid'] }} - uid: {{ user['uid'] }}
{% endif %} {% endif -%}
{% if 'prime_group' in user and 'gid' in user['prime_group'] -%}
- gid: {{ user['prime_group']['gid'] }}
{% else -%}
- gid_from_name: True - gid_from_name: True
{% endif -%}
{% if 'fullname' in user %} {% if 'fullname' in user %}
- fullname: {{ user['fullname'] }} - fullname: {{ user['fullname'] }}
{% endif %} {% endif -%}
- groups: - groups:
- {{ name }} - {{ user_group }}
{% for group in user.get('groups', []) %} {% for group in user.get('groups', []) -%}
- {{ group }} - {{ group }}
{% endfor %} {% endfor %}
- require: - require:
- group: {{ name }} - group: {{ user_group }}
{% for group in user.get('groups', []) %} {% for group in user.get('groups', []) -%}
- group: {{ group }} - group: {{ group }}
{% endfor %} {% endfor %}
user_keydir_{{ name }}: user_keydir_{{ name }}:
file.directory: file.directory:
- name: {{ user.get('home', '/home/{0}'.format(name)) }}/.ssh - name: {{ user.get('home', '/home/{0}'.format(name)) }}/.ssh
- user: {{ name }} - user: {{ name }}
- group: {{ name }} - group: {{ user_group }}
- makedirs: True - makedirs: True
- mode: 744 - mode: 744
- require: - require:
- user: {{ name }} - user: {{ name }}
- group: {{ name }} - group: {{ user_group }}
{% for group in user.get('groups', []) %} {%- for group in user.get('groups', []) %}
- group: {{ group }} - group: {{ group }}
{% endfor %} {%- endfor %}
{% if 'privkey' in user %} {% if 'privkey' in user %}
user_{{ name }}_private_key: user_{{ name }}_private_key:
file.managed: file.managed:
- name: {{ user.get('home', '/home/{0}'.format(name)) }}/.ssh/id_rsa - name: {{ user.get('home', '/home/{0}'.format(name)) }}/.ssh/id_rsa
- user: {{ name }} - user: {{ name }}
- group: {{ name }} - group: {{ user_group }}
- mode: 600 - mode: 600
- source: salt://keys/{{ user['privkey'] }} - source: salt://keys/{{ user['privkey'] }}
- require: - require: