2014-05-30 05:20:13 +02:00
|
|
|
# vim: sts=2 ts=2 sw=2 et ai
|
|
|
|
{% from "users/map.jinja" import users with context %}
|
2014-07-28 18:48:08 +02:00
|
|
|
{% set used_sudo = False %}
|
2013-06-19 21:53:46 +02:00
|
|
|
|
2014-04-23 13:38:31 +02:00
|
|
|
{% for name, user in pillar.get('users', {}).items() if user.absent is not defined or not user.absent %}
|
2014-01-13 16:23:46 +01:00
|
|
|
{%- 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 %}
|
2013-06-19 21:53:46 +02:00
|
|
|
|
|
|
|
{% for group in user.get('groups', []) %}
|
2014-01-14 15:00:41 +01:00
|
|
|
{{ name }}_{{ group }}_group:
|
2013-06-19 21:53:46 +02:00
|
|
|
group:
|
|
|
|
- name: {{ group }}
|
|
|
|
- present
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{{ name }}_user:
|
2014-12-31 09:46:03 +01:00
|
|
|
{% if user.get('createhome', True) %}
|
2013-06-19 21:53:46 +02:00
|
|
|
file.directory:
|
|
|
|
- name: {{ home }}
|
|
|
|
- user: {{ name }}
|
2014-01-13 16:23:46 +01:00
|
|
|
- group: {{ user_group }}
|
2014-08-05 14:02:44 +02:00
|
|
|
- mode: {{ user.get('user_dir_mode', '0750') }}
|
2013-06-19 21:53:46 +02:00
|
|
|
- require:
|
|
|
|
- user: {{ name }}
|
2014-01-13 16:23:46 +01:00
|
|
|
- group: {{ user_group }}
|
2014-12-22 14:32:41 +01:00
|
|
|
{%- endif %}
|
2013-06-19 21:53:46 +02:00
|
|
|
group.present:
|
2014-01-13 16:23:46 +01:00
|
|
|
- name: {{ user_group }}
|
|
|
|
{%- if 'prime_group' in user and 'gid' in user['prime_group'] %}
|
|
|
|
- gid: {{ user['prime_group']['gid'] }}
|
|
|
|
{%- elif 'uid' in user %}
|
2013-10-28 21:39:55 +01:00
|
|
|
- gid: {{ user['uid'] }}
|
2014-01-13 16:23:46 +01:00
|
|
|
{%- endif %}
|
2013-06-19 21:53:46 +02:00
|
|
|
user.present:
|
|
|
|
- name: {{ name }}
|
|
|
|
- home: {{ home }}
|
2014-09-11 17:03:14 +02:00
|
|
|
- shell: {{ user.get('shell', users.get('shell', '/bin/bash')) }}
|
2013-06-19 21:53:46 +02:00
|
|
|
{% if 'uid' in user -%}
|
|
|
|
- uid: {{ user['uid'] }}
|
2014-01-13 16:23:46 +01:00
|
|
|
{% endif -%}
|
2014-04-25 04:45:04 +02:00
|
|
|
{% if 'password' in user -%}
|
2014-12-17 22:57:54 +01:00
|
|
|
- password: '{{ user['password'] }}'
|
2014-04-25 04:45:04 +02:00
|
|
|
{% endif -%}
|
2014-01-13 16:23:46 +01:00
|
|
|
{% if 'prime_group' in user and 'gid' in user['prime_group'] -%}
|
|
|
|
- gid: {{ user['prime_group']['gid'] }}
|
|
|
|
{% else -%}
|
2013-06-19 21:53:46 +02:00
|
|
|
- gid_from_name: True
|
2014-01-13 16:23:46 +01:00
|
|
|
{% endif -%}
|
2013-06-19 21:53:46 +02:00
|
|
|
{% if 'fullname' in user %}
|
|
|
|
- fullname: {{ user['fullname'] }}
|
2014-01-13 16:23:46 +01:00
|
|
|
{% endif -%}
|
2014-09-07 07:23:06 +02:00
|
|
|
{% if not user.get('createhome', True) %}
|
|
|
|
- createhome: False
|
|
|
|
{% endif %}
|
2014-12-22 14:22:46 +01:00
|
|
|
{% if 'expire' in user -%}
|
|
|
|
- expire: {{ user['expire'] }}
|
|
|
|
{% endif -%}
|
2014-10-15 04:05:00 +02:00
|
|
|
- remove_groups: {{ user.get('remove_groups', 'False') }}
|
2013-06-19 21:53:46 +02:00
|
|
|
- groups:
|
2014-01-13 16:23:46 +01:00
|
|
|
- {{ user_group }}
|
|
|
|
{% for group in user.get('groups', []) -%}
|
|
|
|
- {{ group }}
|
2013-06-19 21:53:46 +02:00
|
|
|
{% endfor %}
|
|
|
|
- require:
|
2014-01-13 16:23:46 +01:00
|
|
|
- group: {{ user_group }}
|
|
|
|
{% for group in user.get('groups', []) -%}
|
|
|
|
- group: {{ group }}
|
2013-06-19 21:53:46 +02:00
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
user_keydir_{{ name }}:
|
|
|
|
file.directory:
|
|
|
|
- name: {{ user.get('home', '/home/{0}'.format(name)) }}/.ssh
|
|
|
|
- user: {{ name }}
|
2014-01-13 16:23:46 +01:00
|
|
|
- group: {{ user_group }}
|
2013-06-19 21:53:46 +02:00
|
|
|
- makedirs: True
|
2014-02-14 14:13:17 +01:00
|
|
|
- mode: 700
|
2013-06-19 21:53:46 +02:00
|
|
|
- require:
|
|
|
|
- user: {{ name }}
|
2014-01-13 16:23:46 +01:00
|
|
|
- group: {{ user_group }}
|
|
|
|
{%- for group in user.get('groups', []) %}
|
2013-06-19 21:53:46 +02:00
|
|
|
- group: {{ group }}
|
2014-01-13 16:23:46 +01:00
|
|
|
{%- endfor %}
|
2013-06-19 21:53:46 +02:00
|
|
|
|
2014-01-30 03:53:09 +01:00
|
|
|
{% if 'ssh_keys' in user %}
|
2014-01-31 20:44:41 +01:00
|
|
|
{% set key_type = 'id_' + user.get('ssh_key_type', 'rsa') %}
|
2013-06-19 21:53:46 +02:00
|
|
|
user_{{ name }}_private_key:
|
|
|
|
file.managed:
|
2014-01-31 20:44:41 +01:00
|
|
|
- name: {{ user.get('home', '/home/{0}'.format(name)) }}/.ssh/{{ key_type }}
|
2013-06-19 21:53:46 +02:00
|
|
|
- user: {{ name }}
|
2014-01-13 16:23:46 +01:00
|
|
|
- group: {{ user_group }}
|
2013-06-19 21:53:46 +02:00
|
|
|
- mode: 600
|
2014-05-13 18:37:38 +02:00
|
|
|
- show_diff: False
|
2014-02-17 05:34:47 +01:00
|
|
|
- contents_pillar: users:{{ name }}:ssh_keys:privkey
|
2013-06-19 21:53:46 +02:00
|
|
|
- require:
|
|
|
|
- user: {{ name }}_user
|
|
|
|
{% for group in user.get('groups', []) %}
|
2014-01-14 15:00:41 +01:00
|
|
|
- group: {{ name }}_{{ group }}_group
|
2013-06-19 21:53:46 +02:00
|
|
|
{% endfor %}
|
|
|
|
user_{{ name }}_public_key:
|
|
|
|
file.managed:
|
2014-01-31 20:44:41 +01:00
|
|
|
- name: {{ user.get('home', '/home/{0}'.format(name)) }}/.ssh/{{ key_type }}.pub
|
2013-06-19 21:53:46 +02:00
|
|
|
- user: {{ name }}
|
2014-01-30 05:00:03 +01:00
|
|
|
- group: {{ user_group }}
|
2013-06-19 21:53:46 +02:00
|
|
|
- mode: 644
|
2014-05-13 18:37:38 +02:00
|
|
|
- show_diff: False
|
2014-03-30 17:00:17 +02:00
|
|
|
- contents_pillar: users:{{ name }}:ssh_keys:pubkey
|
2013-06-19 21:53:46 +02:00
|
|
|
- require:
|
|
|
|
- user: {{ name }}_user
|
|
|
|
{% for group in user.get('groups', []) %}
|
2014-01-14 15:00:41 +01:00
|
|
|
- group: {{ name }}_{{ group }}_group
|
2013-06-19 21:53:46 +02:00
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
|
2014-04-23 13:38:31 +02:00
|
|
|
{% if 'ssh_auth' in user %}
|
|
|
|
{% for auth in user['ssh_auth'] %}
|
2013-06-19 21:53:46 +02:00
|
|
|
ssh_auth_{{ name }}_{{ loop.index0 }}:
|
|
|
|
ssh_auth.present:
|
|
|
|
- user: {{ name }}
|
|
|
|
- name: {{ auth }}
|
|
|
|
- require:
|
|
|
|
- file: {{ name }}_user
|
|
|
|
- user: {{ name }}_user
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
|
2014-08-03 01:40:27 +02:00
|
|
|
{% if 'ssh_auth.absent' in user %}
|
|
|
|
{% for auth in user['ssh_auth.absent'] %}
|
|
|
|
ssh_auth_delete_{{ name }}_{{ loop.index0 }}:
|
|
|
|
ssh_auth.absent:
|
|
|
|
- user: {{ name }}
|
|
|
|
- name: {{ auth }}
|
|
|
|
- require:
|
|
|
|
- file: {{ name }}_user
|
|
|
|
- user: {{ name }}_user
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2013-06-19 21:53:46 +02:00
|
|
|
|
2013-10-28 21:39:55 +01:00
|
|
|
{% if 'sudouser' in user and user['sudouser'] %}
|
2014-07-28 18:48:08 +02:00
|
|
|
{% if not used_sudo %}
|
|
|
|
{% set used_sudo = True %}
|
|
|
|
include:
|
|
|
|
- users.sudo
|
|
|
|
{% endif %}
|
|
|
|
|
2013-10-28 21:39:55 +01:00
|
|
|
sudoer-{{ name }}:
|
|
|
|
file.managed:
|
2014-10-25 04:57:44 +02:00
|
|
|
- name: {{ users.sudoers_dir }}/{{ name }}
|
2013-10-28 21:39:55 +01:00
|
|
|
- user: root
|
2014-05-30 05:20:13 +02:00
|
|
|
- group: {{ users.root_group }}
|
2013-10-28 21:39:55 +01:00
|
|
|
- mode: '0440'
|
2014-02-22 09:43:52 +01:00
|
|
|
{% if 'sudo_rules' in user %}
|
2014-04-28 16:52:43 +02:00
|
|
|
{% for rule in user['sudo_rules'] %}
|
|
|
|
"validate {{ name }} sudo rule {{ loop.index0 }} {{ name }} {{ rule }}":
|
|
|
|
cmd.run:
|
2014-08-03 01:06:02 +02:00
|
|
|
- name: 'visudo -cf - <<<"$rule" | { read output; if [[ $output != "stdin: parsed OK" ]] ; then echo $output ; fi }'
|
|
|
|
- stateful: True
|
2014-05-30 05:20:13 +02:00
|
|
|
- shell: {{ users.visudo_shell }}
|
2014-04-28 16:52:43 +02:00
|
|
|
- env:
|
|
|
|
# Specify the rule via an env var to avoid shell quoting issues.
|
|
|
|
- rule: "{{ name }} {{ rule }}"
|
|
|
|
- require_in:
|
2014-10-25 04:57:44 +02:00
|
|
|
- file: {{ users.sudoers_dir }}/{{ name }}
|
2014-04-28 16:52:43 +02:00
|
|
|
{% endfor %}
|
|
|
|
|
2014-10-25 04:57:44 +02:00
|
|
|
{{ users.sudoers_dir }}/{{ name }}:
|
2014-05-13 18:36:49 +02:00
|
|
|
file.managed:
|
|
|
|
- contents: |
|
|
|
|
{%- for rule in user['sudo_rules'] %}
|
|
|
|
{{ name }} {{ rule }}
|
|
|
|
{%- endfor %}
|
2014-02-22 09:43:52 +01:00
|
|
|
- require:
|
|
|
|
- file: sudoer-defaults
|
|
|
|
- file: sudoer-{{ name }}
|
|
|
|
{% endif %}
|
2013-10-28 21:39:55 +01:00
|
|
|
{% else %}
|
2014-10-25 04:57:44 +02:00
|
|
|
{{ users.sudoers_dir }}/{{ name }}:
|
2013-10-28 21:39:55 +01:00
|
|
|
file.absent:
|
2014-10-25 04:57:44 +02:00
|
|
|
- name: {{ users.sudoers_dir }}/{{ name }}
|
2013-06-19 21:53:46 +02:00
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% endfor %}
|
|
|
|
|
2014-04-23 13:38:31 +02:00
|
|
|
{% for name, user in pillar.get('users', {}).items() if user.absent is defined and user.absent %}
|
|
|
|
{{ name }}:
|
|
|
|
{% if 'purge' in user or 'force' in user %}
|
|
|
|
user.absent:
|
|
|
|
{% if 'purge' in user %}
|
|
|
|
- purge: {{ user['purge'] }}
|
|
|
|
{% endif %}
|
|
|
|
{% if 'force' in user %}
|
|
|
|
- force: {{ user['force'] }}
|
|
|
|
{% endif %}
|
|
|
|
{% else %}
|
|
|
|
user.absent
|
|
|
|
{% endif -%}
|
2014-10-25 04:57:44 +02:00
|
|
|
{{ users.sudoers_dir }}/{{ name }}:
|
2014-04-23 13:38:31 +02:00
|
|
|
file.absent:
|
2014-10-25 04:57:44 +02:00
|
|
|
- name: {{ users.sudoers_dir }}/{{ name }}
|
2014-04-23 13:38:31 +02:00
|
|
|
{% endfor %}
|
|
|
|
|
2013-06-19 21:53:46 +02:00
|
|
|
{% for user in pillar.get('absent_users', []) %}
|
|
|
|
{{ user }}:
|
|
|
|
user.absent
|
2014-10-25 04:57:44 +02:00
|
|
|
{{ users.sudoers_dir }}/{{ user }}:
|
2013-10-28 21:39:55 +01:00
|
|
|
file.absent:
|
2014-10-25 04:57:44 +02:00
|
|
|
- name: {{ users.sudoers_dir }}/{{ user }}
|
2013-06-19 21:53:46 +02:00
|
|
|
{% endfor %}
|
2014-03-15 00:07:22 +01:00
|
|
|
|
|
|
|
{% for group in pillar.get('absent_groups', []) %}
|
|
|
|
{{ group }}:
|
|
|
|
group.absent
|
|
|
|
{% endfor %}
|
|
|
|
|