Merge branch 'master' of https://github.com/saltstack-formulas/users-formula
This commit is contained in:
commit
5985275022
16
README.rst
16
README.rst
@ -19,7 +19,7 @@ Available states
|
|||||||
``users``
|
``users``
|
||||||
---------
|
---------
|
||||||
|
|
||||||
Configure a user's home directory, group, the user itself, secondary groups,
|
Configures a user's home directory, group, the user itself, secondary groups,
|
||||||
and associated keys. Also configures sudo access, and absent users.
|
and associated keys. Also configures sudo access, and absent users.
|
||||||
|
|
||||||
``users.sudo``
|
``users.sudo``
|
||||||
@ -31,21 +31,21 @@ is configured.
|
|||||||
``users.bashrc``
|
``users.bashrc``
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
Ensures the bashrc file exists in the users home directory. Set manage_bashrc:
|
Ensures the bashrc file exists in the users home directory. Sets 'manage_bashrc:
|
||||||
True in pillar per user. Defaults to False
|
True' in pillar per user. Defaults to False.
|
||||||
|
|
||||||
``users.profile``
|
``users.profile``
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
Ensures the profile file exists in the users home directory. Set manage_profile:
|
Ensures the profile file exists in the users home directory. Sets 'manage_profile:
|
||||||
True in pillar per user. Defaults to False
|
True' in pillar per user. Defaults to False.
|
||||||
|
|
||||||
``users.vimrc``
|
``users.vimrc``
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
Ensures the vimrc file exists in the users home directory. Set manage_vimrc:
|
Ensures the vimrc file exists in the users home directory. Sets 'manage_vimrc:
|
||||||
True in pillar per user. Defaults to False
|
True' in pillar per user. Defaults to False.
|
||||||
This depends on the vim-formula to be installed
|
This depends on the vim-formula to be installed.
|
||||||
|
|
||||||
``users.user_files``
|
``users.user_files``
|
||||||
---------------
|
---------------
|
||||||
|
@ -11,9 +11,11 @@ users:
|
|||||||
# WARNING: If 'empty_password' is set to True, the 'password' statement
|
# WARNING: If 'empty_password' is set to True, the 'password' statement
|
||||||
# will be ignored by enabling password-less login for the user.
|
# will be ignored by enabling password-less login for the user.
|
||||||
empty_password: False
|
empty_password: False
|
||||||
|
system: False
|
||||||
home: /custom/buser
|
home: /custom/buser
|
||||||
homedir_owner: buser
|
homedir_owner: buser
|
||||||
homedir_group: primarygroup
|
homedir_group: primarygroup
|
||||||
|
user_dir_mode: 750
|
||||||
createhome: True
|
createhome: True
|
||||||
roomnumber: "A-1"
|
roomnumber: "A-1"
|
||||||
workphone: "(555) 555-5555"
|
workphone: "(555) 555-5555"
|
||||||
@ -36,11 +38,15 @@ users:
|
|||||||
sudo_defaults:
|
sudo_defaults:
|
||||||
- '!requiretty'
|
- '!requiretty'
|
||||||
shell: /bin/bash
|
shell: /bin/bash
|
||||||
|
remove_groups: False
|
||||||
prime_group:
|
prime_group:
|
||||||
name: primarygroup
|
name: primarygroup
|
||||||
gid: 500
|
gid: 500
|
||||||
groups:
|
groups:
|
||||||
- users
|
- users
|
||||||
|
optional_groups:
|
||||||
|
- some_groups_that_might
|
||||||
|
- not_exist_on_all_minions
|
||||||
ssh_key_type: rsa
|
ssh_key_type: rsa
|
||||||
# You can inline the private keys ...
|
# You can inline the private keys ...
|
||||||
ssh_keys:
|
ssh_keys:
|
||||||
|
@ -3,10 +3,11 @@ include:
|
|||||||
- 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 -%}
|
||||||
|
@ -38,7 +38,8 @@ include:
|
|||||||
{%- 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 -%}
|
||||||
@ -73,10 +74,13 @@ users_{{ name }}_user:
|
|||||||
{%- elif 'uid' in user %}
|
{%- elif 'uid' in user %}
|
||||||
- gid: {{ user['uid'] }}
|
- gid: {{ user['uid'] }}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
{% if 'system' in user and user['system'] %}
|
||||||
|
- system: True
|
||||||
|
{% endif %}
|
||||||
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 -%}
|
||||||
@ -131,6 +135,12 @@ users_{{ name }}_user:
|
|||||||
{% for group in user.get('groups', []) -%}
|
{% for group in user.get('groups', []) -%}
|
||||||
- {{ group }}
|
- {{ group }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% if 'optional_groups' in user %}
|
||||||
|
- optional_groups:
|
||||||
|
{% for optional_group in user['optional_groups'] -%}
|
||||||
|
- {{optional_group}}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
- require:
|
- require:
|
||||||
- group: {{ user_group }}
|
- group: {{ user_group }}
|
||||||
{% for group in user.get('groups', []) -%}
|
{% for group in user.get('groups', []) -%}
|
||||||
@ -146,7 +156,7 @@ users_{{ name }}_user:
|
|||||||
'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
|
||||||
@ -163,8 +173,7 @@ user_keydir_{{ name }}:
|
|||||||
{% 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',
|
- name: {{ home }}/.ssh/{{ key_type }}
|
||||||
'/home/{0}'.format(name)) }}/.ssh/{{ key_type }}
|
|
||||||
- user: {{ name }}
|
- user: {{ name }}
|
||||||
- group: {{ user_group }}
|
- group: {{ user_group }}
|
||||||
- mode: 600
|
- mode: 600
|
||||||
@ -177,8 +186,7 @@ users_user_{{ name }}_private_key:
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
users_user_{{ name }}_public_key:
|
users_user_{{ name }}_public_key:
|
||||||
file.managed:
|
file.managed:
|
||||||
- name: {{ user.get('home',
|
- name: {{ home }}/.ssh/{{ key_type }}.pub
|
||||||
'/home/{0}'.format(name)) }}/.ssh/{{ key_type }}.pub
|
|
||||||
- user: {{ name }}
|
- user: {{ name }}
|
||||||
- group: {{ user_group }}
|
- group: {{ user_group }}
|
||||||
- mode: 644
|
- mode: 644
|
||||||
@ -204,9 +212,8 @@ users_authorized_keys_{{ name }}:
|
|||||||
{{ auth }}
|
{{ auth }}
|
||||||
{% endfor -%}
|
{% endfor -%}
|
||||||
{% else %}
|
{% else %}
|
||||||
- contents: |
|
{%- for key_name, pillar_name in user['ssh_auth_pillar'].items() %}
|
||||||
{%- for key_name, pillar_name in user['ssh_auth_pillar'].iteritems() %}
|
- contents_pillar: {{ pillar_name }}:{{ key_name }}:pubkey
|
||||||
{{ salt['pillar.get'](pillar_name + ':' + key_name + ':pubkey', '') }}
|
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -218,7 +225,7 @@ users_ssh_auth_{{ name }}_{{ loop.index0 }}:
|
|||||||
- user: {{ name }}
|
- user: {{ name }}
|
||||||
- name: {{ auth }}
|
- name: {{ auth }}
|
||||||
- require:
|
- require:
|
||||||
- file: users_{{ name }}_user
|
- file: user_keydir_{{ name }}
|
||||||
- user: users_{{ name }}_user
|
- user: users_{{ name }}_user
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -227,8 +234,7 @@ users_ssh_auth_{{ name }}_{{ loop.index0 }}:
|
|||||||
{% 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',
|
- name: {{ home }}/.ssh/{{ key_name }}
|
||||||
'/home/{0}'.format(name)) }}/.ssh/{{ key_name }}
|
|
||||||
- user: {{ name }}
|
- user: {{ name }}
|
||||||
- group: {{ user_group }}
|
- group: {{ user_group }}
|
||||||
- mode: 600
|
- mode: 600
|
||||||
@ -241,8 +247,7 @@ user_ssh_keys_files_{{ name }}_{{ key_name }}_private_key:
|
|||||||
{% 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',
|
- name: {{ home }}/.ssh/{{ key_name }}.pub
|
||||||
'/home/{0}'.format(name)) }}/.ssh/{{ key_name }}.pub
|
|
||||||
- user: {{ name }}
|
- user: {{ name }}
|
||||||
- group: {{ user_group }}
|
- group: {{ user_group }}
|
||||||
- mode: 644
|
- mode: 644
|
||||||
@ -336,6 +341,7 @@ users_ssh_known_hosts_delete_{{ name }}_{{ loop.index0 }}:
|
|||||||
|
|
||||||
users_sudoer-{{ name }}:
|
users_sudoer-{{ name }}:
|
||||||
file.managed:
|
file.managed:
|
||||||
|
- replace: False
|
||||||
- name: {{ users.sudoers_dir }}/{{ name }}
|
- name: {{ users.sudoers_dir }}/{{ name }}
|
||||||
- user: root
|
- user: root
|
||||||
- group: {{ users.root_group }}
|
- group: {{ users.root_group }}
|
||||||
@ -374,6 +380,7 @@ users_sudoer-{{ name }}:
|
|||||||
|
|
||||||
users_{{ users.sudoers_dir }}/{{ name }}:
|
users_{{ users.sudoers_dir }}/{{ name }}:
|
||||||
file.managed:
|
file.managed:
|
||||||
|
- replace: True
|
||||||
- name: {{ users.sudoers_dir }}/{{ name }}
|
- name: {{ users.sudoers_dir }}/{{ name }}
|
||||||
- contents: |
|
- contents: |
|
||||||
{%- if 'sudo_defaults' in user %}
|
{%- if 'sudo_defaults' in user %}
|
||||||
@ -382,6 +389,11 @@ users_{{ users.sudoers_dir }}/{{ name }}:
|
|||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- if 'sudo_rules' in user %}
|
{%- if 'sudo_rules' in user %}
|
||||||
|
########################################################################
|
||||||
|
# File managed by Salt (users-formula).
|
||||||
|
# Your changes will be overwritten.
|
||||||
|
########################################################################
|
||||||
|
#
|
||||||
{%- for rule in user['sudo_rules'] %}
|
{%- for rule in user['sudo_rules'] %}
|
||||||
{{ name }} {{ rule }}
|
{{ name }} {{ rule }}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
@ -466,7 +478,8 @@ users_{{ users.sudoers_dir }}/{{ name }}:
|
|||||||
|
|
||||||
{% for user in pillar.get('absent_users', []) %}
|
{% for user in pillar.get('absent_users', []) %}
|
||||||
users_absent_user_2_{{ user }}:
|
users_absent_user_2_{{ user }}:
|
||||||
user.absent
|
user.absent:
|
||||||
|
- name: {{ name }}
|
||||||
users_2_{{ users.sudoers_dir }}/{{ user }}:
|
users_2_{{ users.sudoers_dir }}/{{ user }}:
|
||||||
file.absent:
|
file.absent:
|
||||||
- name: {{ users.sudoers_dir }}/{{ user }}
|
- name: {{ users.sudoers_dir }}/{{ user }}
|
||||||
|
@ -3,10 +3,11 @@ include:
|
|||||||
- 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 -%}
|
||||||
|
@ -5,9 +5,10 @@ include:
|
|||||||
|
|
||||||
{% 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 -%}
|
||||||
|
@ -4,10 +4,11 @@ include:
|
|||||||
- 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…
Reference in New Issue
Block a user