How do you create a user with a hashed password using the `user` module?
IntermediateConceptAd-hoc Commands, Modules and Idempotency
Answer
The password parameter needs a hash, never plain text. Generate it with the password_hash filter.
- ansible.builtin.user:
name: deploy
shell: /bin/bash
groups: [sudo]
append: true
password: "{{ vault_deploy_password | password_hash('sha512', 'fixedsalt') }}"
update_password: on_create
Without a fixed salt a new random hash is made each run and the task reports changed every time. update_password: on_create also avoids resetting passwords users changed. For SSH access, prefer ansible.posix.authorized_key.
More on Ad-hoc Commands, Modules and Idempotency
What is an ad-hoc command and what is its syntax?BeginnerWhat does `ansible all -m ping` actually test?BeginnerGive practical use cases for ad-hoc commands.IntermediateWhat is the difference between the `command` and `shell` modules?BeginnerCompare `raw`, `command`, `shell` and `script`.IntermediateWhy prefer a dedicated module over `shell`/`command`?Beginner