Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible update user password

Tags:

ansible

ansible 192.168.1.115 -s -m shell -a "echo -e 'oldpassword\nnewpassword\nnewpassword' | passwd myuser" -u myuser --ask-sudo-pass

I would like to update existing user with new password, I had tried this command, but it doesn't work

appreciate any Tips !

like image 423
Roy Tan Avatar asked Jun 15 '16 07:06

Roy Tan


People also ask

How do I change my Ansible password?

The only required is “name”, which is the username. In the parameter “state” we need to specify “present” options, obviously, we can't change a password of a non-existent account. The most important parameter is “password” which allows you to specify the new password. For macOS target, the password is in cleartext.

How do I change my Ansible username and password?

As you can see from the above example, in ansible, to specify the username and password to use for your remote hosts, we use the -u [username] and –ask-pass for the password.


1 Answers

You can leverage the user module to quickly change the password for desired account. Ansible doesn’t allow you to pass a cleartext password to user module so you have to install a password hashing library to be leveraged by Python.

To install the library:

sudo -H pip install passlib

Then simply exexute your command:

ansible 192.168.1.115 -s -m user -a "name=root update_password=always password={{ yourpassword | password_hash('sha512') }}" -u myuser --ask-sudo-pass

Hope that help you

like image 67
Arbab Nazar Avatar answered Oct 23 '22 11:10

Arbab Nazar