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