An Ansible project that declares people's accounts on your servers (name, public
SSH key, groups, sudo and a state of active | locked | removed). Every new
account, lock or removal is a Git commit, so git log becomes your audit trail.
Full article, with tests and real output on Ubuntu 24.04 and Debian 13 (in Brazilian Portuguese): https://www.linuxpro.com.br/2026/09/usuarios-linux-ansible-ssh-sudo-git/
A complete, tested version of this project, packaged as a reusable role with validation, integration tests and CI, lives at https://github.com/jniltinho/ansible-linux-users
Gists have no folders; in the project the files live here:
users-linux/
├── .gitignore
├── ansible.cfg
├── inventory.ini
├── users.yml # playbook
├── templates/
│ └── sudoers.j2 # <- sudoers.j2
└── group_vars/
└── all/
├── users.yml # <- group_vars_all_users.yml
└── vault.yml # <- group_vars_all_vault.example.yml (encrypt it!)
mkdir -p users-linux/templates users-linux/group_vars/all && cd users-linux
# copy the files to the paths above, then edit inventory.ini and the user list
echo 'a-long-passphrase' > ~/.vault-pass-users && chmod 600 ~/.vault-pass-users
openssl passwd -6 # hash for the initial password (sudo with password)
ansible-vault encrypt group_vars/all/vault.yml
git init -b main && git add -A && git commit -m "Initial layout"
ansible-lint
ansible-playbook users.yml --check --diff
ansible-playbook users.ymlRequires the ansible package (it ships the ansible.posix collection).
Tested with ansible 9.2.0 / ansible-core 2.16.3.
- Never commit a private key or a plain-text password.
- Never delete an entry from the list: change its
statetoremoved. - Lock before removing.
usermod -Lonly locks the password; what actually blocks SSH key logins is account expiration (expires). append: truenever removes a user from a group that left the list; run once withappend: falsewhen you need to take a group away.- The keys in this example are public keys generated only for a lab; the IP addresses are documentation addresses (192.0.2.0/24).