# changing a password with ansible

**URL:** <https://forum.ansible.com/t/changing-a-password-with-ansible/35336>\
**Category:** Ansible Project\
**Tags:** rhel, fedora\
**Created:** [June 11, 2021, 6:59pm UTC](https://forum.ansible.com/t/changing-a-password-with-ansible/35336 "2021-06-11T18:59:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joost\_Ringoot](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@Joost\_Ringoot](https://forum.ansible.com/u/Joost_Ringoot)\
**Post date:** [June 11, 2021, 6:59pm UTC](https://forum.ansible.com/t/changing-a-password-with-ansible/35336/1 "2021-06-11T18:59:25Z")

</div>

Hello,

I am trying to change a password with ansible but it doesn’t work. I don’t see why it is not working. Do you see what is going wrong? see screenshot or cli below

 ![Screenshot from 2021-06-11 20-49-25.png](https://us1.discourse-cdn.com/ansible/original/2X/5/5323dc41a98549ae71e8b478eabace9f3256c65a.png)  
[pipo@install-me ~]$ ansible all -i localhost, -m debug -a “msg={{ ‘Een.voorbeeld.passwoord’ | password\_hash(‘sha512’) }}”  
localhost | SUCCESS =\> {  
“msg”: “$6$sTmb9Vaxxd9fOGyC$AueAkwgO1M.qnKtKrtAFuPN5iTt0h.Dl1DcLSx9a/fqGTpltbuWAB3ZO.wsQOJTH95l3DIz/blpKFDezAzXhL.”  
}  
[pipo@install-me ~]$ ansible localhost -m user -a “name=jopy update\_password=always password={{ ‘$6$sTmb9Vaxxd9fOGyC$AueAkwgO1M.qnKtKrtAFuPN5iTt0h.Dl1DcLSx9a/fqGTpltbuWAB3ZO.wsQOJTH95l3DIz/blpKFDezAzXhL.’ | password\_hash(‘sha512’) }}” -u root  
localhost | CHANGED =\> {  
“ansible\_facts”: {  
“discovered\_interpreter\_python”: “/usr/bin/python”  
},  
“append”: false,  
“changed”: true,  
“comment”: “”,  
“group”: 1004,  
“home”: “/home/jopy”,  
“move\_home”: false,  
“name”: “jopy”,  
“password”: “NOT\_LOGGING\_PASSWORD”,  
“shell”: “/bin/bash”,  
“state”: “present”,  
“uid”: 1004  
}  
[pipo@install-me ~]$ su - jopy  
Password:  
su: Authentication failure  
[pipo@install-me ~]$ exit  
logout  
[root@install-me ~]# passwd jopy  
Changing password for user jopy.  
New password:  
Retype new password:  
passwd: all authentication tokens updated successfully.  
[root@install-me ~]# su - pipo  
Last login: Fre Jun 11 20:40:54 CEST 2021 on pts/0  
[pipo@install-me ~]$ su - jopy  
Password:  
Last login: Fri Jun 11 20:42:32 CEST 2021 from localhost on pts/1  
Last failed login: Fri Jun 11 20:48:35 CEST 2021 on pts/0  
There were 3 failed login attempts since the last successful login.  
[jopy@install-me ~]$ ansible --version  
ansible 2.9.21  
config file = /etc/ansible/ansible.cfg  
configured module search path = [u’/home/jopy/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /usr/lib/python2.7/site-packages/ansible  
executable location = /bin/ansible  
python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]  
[jopy@install-me ~]$ cat /etc/\*release  
CentOS Linux release 7.9.2009 (Core)  
NAME=“CentOS Linux”  
VERSION=“7 (Core)”  
ID=“centos”  
ID\_LIKE=“rhel fedora”  
VERSION\_ID=“7”  
PRETTY\_NAME=“CentOS Linux 7 (Core)”  
ANSI\_COLOR=“0;31”  
CPE\_NAME=“cpe:/o:centos:centos:7”  
HOME\_URL=“[https://www.centos.org/](https://www.centos.org/)”  
BUG\_REPORT\_URL=“[https://bugs.centos.org/](https://bugs.centos.org/)”

CENTOS\_MANTISBT\_PROJECT=“CentOS-7”  
CENTOS\_MANTISBT\_PROJECT\_VERSION=“7”  
REDHAT\_SUPPORT\_PRODUCT=“centos”  
REDHAT\_SUPPORT\_PRODUCT\_VERSION=“7”

CentOS Linux release 7.9.2009 (Core)  
CentOS Linux release 7.9.2009 (Core)  
[jopy@install-me ~]$ uname -a  
Linux install-me 3.10.0-1160.6.1.el7.x86\_64 #1 SMP Tue Nov 17 13:59:11 UTC 2020 x86\_64 x86\_64 x86\_64 GNU/Linux  
[jopy@install-me ~]$

Thanks ahead

---

<div class="post-metadata">

**Author:** ![Joost\_Ringoot](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@Joost\_Ringoot](https://forum.ansible.com/u/Joost_Ringoot)\
**Post date:** [June 11, 2021, 7:32pm UTC](https://forum.ansible.com/t/changing-a-password-with-ansible/35336/2 "2021-06-11T19:32:01Z")

</div>

For the record,  
I tried this as well on Debian 10 buster (ansible 2.7) and with the ansible from the backports repository (ansible 2.9)

---

<div class="post-metadata">

**Author:** ![jcpetro](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jcpetro](https://forum.ansible.com/u/jcpetro)\
**Post date:** [June 12, 2021, 1:53am UTC](https://forum.ansible.com/t/changing-a-password-with-ansible/35336/3 "2021-06-12T01:53:17Z")

</div>

Maybe I am reading this wrong, but I think that by you putting the password hash inside {{ }}, that ansible may be interpreting it as a variable. I would have to poke and see if that is the actual case or not.

–John

> **(attachments)**
>
> ![Screenshot from 2021-06-11 20-49-25.png](https://us1.discourse-cdn.com/ansible/original/2X/5/5323dc41a98549ae71e8b478eabace9f3256c65a.png)
