Interview Prep/Ansible/Modules, Idempotency and Handlers

The `user` module reports `changed` on every run for the `password` parameter

AdvancedTroubleshootingModules, Idempotency and Handlers
Answer

Likely causes → password_hash('sha512') generates a random salt each run, so the hash is always different from the one in /etc/shadow.

Fix → Use a stable salt per host, or only set the password when the user is created:

- ansible.builtin.user:
    name: deploy
    password: "{{ deploy_password | password_hash('sha512', deploy_salt) }}"
    update_password: on_create
  no_log: true

Here deploy_salt is a fixed vaulted string of 16 characters or fewer ([./a-zA-Z0-9]).

Prevent → Prefer SSH keys and disable passwords for service accounts. When passwords are required, store the pre-computed hash in Vault.

All Ansible questions Roadmap: Ansible

More on Modules, Idempotency and Handlers