Browse Source

possibility to define alternate user`s prime group

tags/v0.45.0
tiger-seo 11 years ago
parent
commit
5ce8d7d2c5
1 changed files with 34 additions and 22 deletions
  1. +34
    -22
      users/init.sls

+ 34
- 22
users/init.sls 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,58 +24,64 @@ 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', []) %}
- {{ group }}
- {{ user_group }}
{% for group in user.get('groups', []) -%}
- {{ group }}
{% endfor %}
- require:
- group: {{ name }}
{% for group in user.get('groups', []) %}
- group: {{ group }}
- group: {{ user_group }}
{% for group in user.get('groups', []) -%}
- group: {{ group }}
{% endfor %}

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:

Loading…
Cancel
Save