CertGrid CertGrid
Hands-on Lab·Ansible

Ansible Users, Groups and Password Hashes

Creating a user is one module and the parameters are obvious. The password is not: the `password` parameter takes a **hash**, and passing a plain string writes that string into the shadow file as though it were one. Nothing fails, and the account is unusable. This shows the trap, the fix, and the rest of the lifecycle.

Automating Administration Guide 31 of 45 Intermediate

Written against the versions above. This lab is Ubuntu 26.04 and EX294 is a RHEL exam. the `user` and `group` modules are identical on both. `password_hash('sha512')` needs `passlib` on the control node for some algorithms; sha512 works with the standard library. The salt argument makes the hash deterministic, which is what keeps the task idempotent - without it a new hash is generated every run and the task reports change forever.

One managed node. Two users and two groups are created and removed again.
Server NameIP AddressOSRolesCPURAMHDD
ANS-CTL01192.168.0.36Ubuntu 26.04 LTSAnsible Control Node2 Core3 GB50 GB
ANS-A01192.168.0.37Ubuntu 26.04 LTSManaged Node (group: web)2 Core3 GB50 GB

Before you start

  1. The configuration this guide assumes

  2. Groups first, then users

  3. The password trap

  4. Hashing it properly

  5. Keys, locking and removal

Official sources