🤓 Check (otherwise create) that given users and groups are present on the system.
Python installed on the server.
Available customizations:
-
users_init_users
: dictionnary of users to be createdcomment
: description of user inpasswd
file (see GEOS field) (defaut none)create_home
: create a home directory if it doesn’t exist (default according tousers_init_create_home_default
)expires
: epoch time when user will expire.-1
means never (default according tousers_init_expires_default
)generate_ssh_key
: whether to generate SSH key for the user (default according tousers_init_generate_ssh_key_default
)group
: primary group of the user (default none). Must be created manuallygroups
: list of groups the user will be member (default none). It will overrides previous settings (no append). Must be created manuallyhome
: home directory for the user (default according to system)move_home
: move user old home to a new one (default according tousers_init_move_home_default
)non_unique
: allows changing uid (when used with optionuid
) to a non unique one (defaultusers_init_non_unique_default
)password
: the user’s password to this crypted value. (default none)password_lock
: disables login with a password. The user is not disabled, but cannot login by password methods (might besudo su
orssh
, etc.) (default according tousers_init_password_lock_default
)seuser
: sets the seuser type (=user_u=) on selinux enabled systems (default none)shell
: shell used when logging-in (default according tousers_init_shell_default
)skeleton
: sets the home skeleton (template) used to create the home directory (default according to system)uid
: sets the uid of the user (default omitted)ssh_key
: SSH key generation configurationforce
: overwrite old SSH key with a new one (default according tousers_init_ssh_key_force_default
)ssh_key_bits
: size of the key in bits (default according tousers_init_ssh_key_bits_default
)ssh_key_comment
: comment for the SSH key (default omitted)ssh_key_file
: custom user SSH key file path (default omitted)ssh_key_passphrase
: passphrase for accessing the key (default omitted)ssh_key_type
: SSH key algorithm type. This must be provided in order to create the key. Possible values are:rsa
,ed25519
or others depending on the system
-
users_init_system_users
: dictionnary of system users to be created. This has the same structure asusers_init_users
, except default values don’t have theusers_init_
prefix, butusers_init_sysuser_
-
users_init_user_groups
: list of user groups to create. Because groups provided tousers_init_users
won’t be created automatically -
users_init_system_groups
: list of system groups to create. Because groups provided tousers_init_system_users
won’t be created automatically
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- role: notetiene.users-init
users_init_system_users:
dummy:
create_home: no
authorized_keys:
groups:
- dummy
shell: "/bin/sh"users_init_users:
foo:
password: "{{ lookup('passwordstore', 'hostname/foo') | password_hash('sha512', 2645282 | random(seed=inventory_hostname) | string, rounds=165536) }}"
authorized_keys:
ssh_key:
ssh_key_bits: 4096
ssh_key_type: "rsa"
expires: 1422403387
home: "/home/bar/foo"
group: foo
groups:
- bar
shell: "/bin/bash"
users_init_system_groups:
- dummy
users_init_user_groups:
- foo
- bar
MIT
This role was created by Etienne Prud’homme.