# Generating password randomly when user is created

**URL:** <https://forum.ansible.com/t/generating-password-randomly-when-user-is-created/20719>\
**Category:** Ansible Project\
**Created:** [March 1, 2016, 11:04am UTC](https://forum.ansible.com/t/generating-password-randomly-when-user-is-created/20719 "2016-03-01T11:04:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepa\_Yr](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@Deepa\_Yr](https://forum.ansible.com/u/Deepa_Yr)\
**Post date:** [March 1, 2016, 11:04am UTC](https://forum.ansible.com/t/generating-password-randomly-when-user-is-created/20719/1 "2016-03-01T11:04:28Z")

</div>

I am running this task

- name: Create users with auto generated password  
user: name=deepa state=present password=“{{ lookup(‘password’, ‘/tmp/deepapassword.txt chars=ascii\_letters’) }}”

It is creating the file /tmp/deepapassword.txt and I see the password  
But when I try to login as deepa user with that password, it says incorrect password.

Any suggestions here ?

My requirement is to create a user with random password and use this user credentials in the subsequent tasks.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 1, 2016, 1:05pm UTC](https://forum.ansible.com/t/generating-password-randomly-when-user-is-created/20719/2 "2016-03-01T13:05:47Z")

</div>

The user module expects the password to already be encrypted. You will also need to pass encrypt=True to the lookup as well.

---

<div class="post-metadata">

**Author:** ![Deepa\_Yr](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@Deepa\_Yr](https://forum.ansible.com/u/Deepa_Yr)\
**Post date:** [March 1, 2016, 1:29pm UTC](https://forum.ansible.com/t/generating-password-randomly-when-user-is-created/20719/3 "2016-03-01T13:29:12Z")

</div>

I am trying to login as deepa user from putty session to confirm that password is correct or not. I read in the documentation that password lookup generates password in a text format. So I should be able to login from putty session with that password right.

---

<div class="post-metadata">

**Author:** ![Deepa\_Yr](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@Deepa\_Yr](https://forum.ansible.com/u/Deepa_Yr)\
**Post date:** [March 2, 2016, 12:54pm UTC](https://forum.ansible.com/t/generating-password-randomly-when-user-is-created/20719/4 "2016-03-02T12:54:01Z")

</div>

Thanks. Understood what you suggested. It works now.
