# Problem with: create user with an encrypted password

**URL:** <https://forum.ansible.com/t/problem-with-create-user-with-an-encrypted-password/29474>\
**Category:** Ansible Project\
**Created:** [January 18, 2019, 11:54pm UTC](https://forum.ansible.com/t/problem-with-create-user-with-an-encrypted-password/29474 "2019-01-18T23:54:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrik\_Schuetze](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Henrik\_Schuetze](https://forum.ansible.com/u/Henrik_Schuetze)\
**Post date:** [January 18, 2019, 11:54pm UTC](https://forum.ansible.com/t/problem-with-create-user-with-an-encrypted-password/29474/1 "2019-01-18T23:54:36Z")

</div>

Hello,

i want to create users on a centos system. the users use rsa keys to authenticate on the linux.  
They have an PAM token to connect on the maria db on the system.  
And with PAM they need an Linux password and the token to login to the maria.

The Users need no password to connect to the centos.  
But the maria with PAM autentication need an correct linux password (and that is ok).

So i begin:

- name: add 2factorauth users  
user:  
name: “{{ item.user }}”  
password: “{{ ‘{{ item.user }}’ | password\_hash(‘sha512’) }}”  
update\_password : on\_create  
state: present  
shell: /bin/bash  
system: no  
createhome: yes  
home: “/home/{{ item.user }}”  
with\_items: “{{ two\_factor\_users }}”

This should generate a user with a password on a linux system.  
And yes it generate a user. and yes this user has a password (encrypted in the /etc/shadow) but the user cant use this password to login to the maria.

if the user want to change the password with passwd he gets the error: authentication token manipulation error  
So it seems the encrypted password is not correct. If i use my root account and create a new password for the user with passwd -f , the user can login to the mariadb with the password.

I checked the password encryption method on the linux instance. And yes this is sha512

What is wrong?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 19, 2019, 8:23am UTC](https://forum.ansible.com/t/problem-with-create-user-with-an-encrypted-password/29474/2 "2019-01-19T08:23:35Z")

</div>

The user you creating has the password  
{{ item.user }}

And yes it is literally that string the curly brackets and all.

I don't understand what password you are trying to set for the user, if you are trying to set the password the same as the username this is the correct syntax

&nbsp;&nbsp;password: "{{ item.user | password\_hash('sha512') }}"

You can't use curly brackets inside curly brackets, you are already inside template mode.

---

<div class="post-metadata">

**Author:** ![Henrik\_Schuetze](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Henrik\_Schuetze](https://forum.ansible.com/u/Henrik_Schuetze)\
**Post date:** [January 19, 2019, 3:11pm UTC](https://forum.ansible.com/t/problem-with-create-user-with-an-encrypted-password/29474/3 "2019-01-19T15:11:26Z")

</div>

Hello Kai,

yes i set the password the same as the username.

And thanx for your help.

Your solution works for me.
