AsavarTzeth.users
Ansible Users Role - ansible-role-users
This is an Ansible role for managing users, groups, SSH keys, and sudo privileges.
The setup for this role is similar to the cloud-init format, using YAML structure for easy understanding. We’ve made some adjustments where necessary:
- Dashes (-) in variable names have been replaced with underscores (_) because of how Ansible handles variable names.
For more details about cloud-init, visit the documentation:
https://cloudinit.readthedocs.io/en/latest/index.html
Requirements
This role works with Ansible versions 2.2.0 and above. It might work on older versions, but we do not support them.
Role Variables
Here are the variables you can customize along with their default values:
users_default_shell
: The default shell for new users, set to/bin/bash
.users_create_primary_group
: If true (which is the default), a primary user group will be created if it doesn't exist. Set to false if you're managing groups differently.users_enable_sudo
: If true (default), allows the user to use sudo. Disable it if sudo is managed differently.users
: The mandatory parameter to define a user.name
: The username.gecos
: Comment field, usually the full name.homedir
: Home directory for the user.primary_group
: The main user group.groups
: Additional groups the user belongs to.no_create_home
: If true, skip creating home directory (defaults to true ifsystem: true
).shell
: User shell (defaults tousers_default_shell
).passwd
: User password (SHA512 hashed).ssh_authorized_keys
: List of SSH public keys for access.sudo
: Sudo privileges for the user.system
: If true, the user is a system user.
Dependencies
There are no dependencies.
Example Playbook
To add or modify a user with sudo and SSH keys:
- hosts: all
roles:
- role: AsavarTzeth.users
users_default_shell: /bin/bash
users_create_primary_group: true
users_enable_sudo: true
users:
- name: foobar1
gecos: Foo B. Bar
primary_group: foobar1
groups: ['users','wheel']
shell: /bin/bash
ssh_authorized_keys:
- "ssh-rsa AAAAA.... foo@host"
- "ssh-rsa AAAAB.... bar@host"
sudo: ALL=(ALL) ALL
To add or modify a system user:
- hosts: all
roles:
- role: AsavarTzeth.users
users:
- name: foobar2
gecos: FooBar Service Account
homedir: /
primary_group: foobar
shell: /sbin/nologin
system: true
To delete users:
- hosts: all
roles:
- role: AsavarTzeth.users
users_deleted:
- name: foobar1
- name: foobar2
To modify a user password:
- hosts: all
roles:
- role: AsavarTzeth.users
users:
- name: foobar1
passwd: $6$mI3A2y4O.YfqhlPt$szsWfnICXsYLbsIghLauJG.I3enLYGDPBYO1DYTHn9gB6y3Q2faM7iqievJlU5ZMTT9X3wHrUv0c7HWkToGBp/
License
This role is licensed under the BSD-2-Clause license.
Author Information
Created by Patrik Nilsson.
ansible-galaxy install AsavarTzeth.users