# ansible-2.9 how to password

**URL:** <https://forum.ansible.com/t/ansible-2-9-how-to-password/36579>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [April 30, 2022, 12:30am UTC](https://forum.ansible.com/t/ansible-2-9-how-to-password/36579 "2022-04-30T00:30:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dimndskier](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dimndskier/32/773_2.png) [@dimndskier](https://forum.ansible.com/u/dimndskier)\
**Post date:** [April 30, 2022, 12:30am UTC](https://forum.ansible.com/t/ansible-2-9-how-to-password/36579/1 "2022-04-30T00:30:40Z")

</div>

I am very new to writing ansible syntax, and am working on writing my first playbook.

I want to set a password that I control for a **user** named **_admin2_** but I cannot find a solid good example for creating the user and setting the password on a RHEL-variant (ALMA Linux):

- name: Add the user admin2  
ansible.builtin.user:  
name: admin2  
**comment:** “Second admin account”  
shell: /bin/bash  
groups: users,wheel  
append: yes

What can I do in a simple ansible play that enables me to set a password value?  
I have seen a few different examples, but I don’t know what to trust.

---

<div class="post-metadata">

**Author:** ![Andrew\_Latham](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@Andrew\_Latham](https://forum.ansible.com/u/Andrew_Latham)\
**Post date:** [April 30, 2022, 1:04am UTC](https://forum.ansible.com/t/ansible-2-9-how-to-password/36579/2 "2022-04-30T01:04:48Z")

</div>

[https://docs.ansible.com/ansible/latest/reference\_appendices/faq.html#how-do-i-generate-encrypted-passwords-for-the-user-module](https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-encrypted-passwords-for-the-user-module) as noted from [https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user\_module.html](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html)

---

<div class="post-metadata">

**Author:** ![dimndskier](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dimndskier/32/773_2.png) [@dimndskier](https://forum.ansible.com/u/dimndskier)\
**Post date:** [May 1, 2022, 4:53am UTC](https://forum.ansible.com/t/ansible-2-9-how-to-password/36579/3 "2022-05-01T04:53:19Z")

</div>

Thanks Andrew, I have read these two pages which is where I got my sample code from in the first place.  
My focus is on the password hash and getting it delivered.

I am guessing I should use a vault file and have a variable reference it. I can do it that way right?

---

<div class="post-metadata">

**Author:** ![Hamza\_Bouabdallah](https://avatars.discourse-cdn.com/v4/letter/h/439d5e/32.png) [@Hamza\_Bouabdallah](https://forum.ansible.com/u/Hamza_Bouabdallah)\
**Post date:** [May 1, 2022, 2:43pm UTC](https://forum.ansible.com/t/ansible-2-9-how-to-password/36579/4 "2022-05-01T14:43:53Z")

</div>

in general, if you don’t know what to trust than trust “testing and experience”, try on your own until you make it !

One way to do it, is to put your password in a var (for example a var named my\_pass) that you can optionally encrypt via vault like you said then use the password directive :

- name: Add the user admin2  
ansible.builtin.user:  
name: admin2  
**password** : {{ my\_pass | password\_hash(‘sha512’) }}  
**comment:** “Second admin account”  
shell: /bin/bash  
groups: users,wheel  
append: yes

if you want more idempotent results, fix the salt used for password generation, this way :  
…

password: {{ my\_pass | password\_hash(‘sha512’, ‘some\_salt’) }}  
…

---

<div class="post-metadata">

**Author:** ![dimndskier](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dimndskier/32/773_2.png) [@dimndskier](https://forum.ansible.com/u/dimndskier)\
**Post date:** [May 4, 2022, 12:08am UTC](https://forum.ansible.com/t/ansible-2-9-how-to-password/36579/5 "2022-05-04T00:08:23Z")

</div>

Thank you for that feedback. I am going to try and make this work.
