This role helps with managing UNIX users from Ansible variables. It allows to add, modify and delete UNIX users with
variable users_config
which is defined as a list where each list item is a dictionary of parameters that will be
passed to Ansible's user
module. For example, to ensure an user for Ansible exists and its
password is locked, define variable users_config
in group_vars
or host_vars
as such:
users_config:
- # Ensure user for Ansible exists and its password is lock
name: '{{ ansible_user }}'
password_lock: true
shell: '/bin/bash'
state: present
Tested OS images
- Cloud image (
amd64
) of Debian 10 (Buster) - Cloud image (
amd64
) of Debian 11 (Bullseye) - Cloud image (
amd64
) of Debian 12 (Bookworm) - Cloud image (
amd64
) of Debian 13 (Trixie) - Cloud image (
amd64
) of CentOS 7 (Core) - Cloud image (
amd64
) of CentOS 8 (Stream) - Cloud image (
amd64
) of CentOS 9 (Stream) - Cloud image (
amd64
) of Fedora Cloud Base 40 - Cloud image (
amd64
) of Ubuntu 18.04 LTS (Bionic Beaver) - Cloud image (
amd64
) of Ubuntu 20.04 LTS (Focal Fossa) - Cloud image (
amd64
) of Ubuntu 22.04 LTS (Jammy Jellyfish) - Cloud image (
amd64
) of Ubuntu 24.04 LTS (Noble Numbat)
Available on Ansible Galaxy in Collection jm1.cloudy.
None.
Name | Default value | Required | Description |
---|---|---|---|
users_config |
[] |
false | List of parameter dictionaries for Ansible's user module |
None.
- hosts: all
become: true
vars:
# Variables are listed here for convenience and illustration.
# In a production setup, variables would be defined e.g. in
# group_vars and/or host_vars of an Ansible inventory.
# Ref.:
# https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html
# https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html
users_config:
- # Ensure user for Ansible exists and its password is lock
name: '{{ ansible_user }}'
password_lock: true
shell: '/bin/bash'
state: present
roles:
- name: Setup local users
role: jm1.cloudy.users
tags: ["jm1.cloudy.users"]
For instructions on how to run Ansible playbooks have look at Ansible's Getting Started Guide.
GNU General Public License v3.0 or later
See LICENSE.md to see the full text.