chasinglogic.ansible_users
ansible-users
This role is used to manage users on a system.
It is a modified version of singleplatform-eng.users because that version appears to be no longer maintained.
Role Configuration
users_create_per_user_group
(default: true) - When creating a user, also create a group with the same name and make it the user's main group.users_group
(default: users) - Ifusers_create_per_user_group
is not set, this will be the main group for all created users.users_default_shell
(default: /bin/bash) - This is the default shell if no specific shell is set for the user.users_create_homedirs
(default: true) - Create home directories for new users. Set to false if you manage home directories in a different way.authorized_keys_file
(default: .ssh/authorized_keys) - Set this if your SSH server uses a different authorized keys file.
Creating Users
To add users, create a variable containing a list of users. A good place for this list is in group_vars/all
or group_vars/groupname
if you want to limit the users to certain machines.
Each user must have the following information:
username
- User’s username.name
- User’s full name (gecos field).home
- User’s home directory (optional; defaults to /home/username).uid
- User’s numeric ID (optional; helpful for consistency across systems).gid
- Group ID (optional; if not specified,uid
will be used).password
- If provided as a hash, it will be used; otherwise, the account will be locked.update_password
- Can be 'always' or 'on_create':- 'always' updates passwords if they are different (default).
- 'on_create' sets passwords only for new users.
group
- Optional alternative primary group.groups
- List of additional groups for the user.append
- If yes, will add groups instead of replacing the existing list (optional).profile
- Custom shell profiles as a string block.ssh_key
- A list of SSH keys for the user (optional; should be direct and without newlines).generate_ssh_key
- Whether to create an SSH key for the user (optional; defaults to no).
The following items are optional for each user:
shell
- User’s shell. Defaults to /bin/bash. You can change the default withusers_default_shell
.
Example:
---
users:
- username: foo
name: Foo Barrington
groups: ['wheel','systemd-journal']
uid: 1001
home: /local/home/foo
profile: |
alias ll='ls -lah'
ssh_key:
- "ssh-rsa AAAAA.... foo@machine"
- "ssh-rsa AAAAB.... foo2@machine"
groups_to_create:
- name: developers
gid: 10000
users_deleted:
- username: bar
name: Bar User
uid: 1002
Deleting Users
The users_deleted
variable lists users that should be removed from the system, and they will be deleted in the next Ansible run. The format is the same as for adding users, but only the username
is required. It’s a good idea to also keep the uid
for reference to avoid reusing numeric user IDs.
You can also choose to remove the user’s home directory and mail spool by using the remove
parameter, and force removal of files with the force
parameter.
users_deleted:
- username: bar
uid: 1002
remove: yes
force: yes
ansible-galaxy install chasinglogic.ansible_users