Ansible to change user password
By Fahad Ahammed
- One minute read - 202 wordsOne of the most basic things to do in a Linux Server. We can use just passwd <user>
to change the password of a user. But to do that in 100s of server can be a tricky one. Ansible is the savior on that perspective.
---
- hosts: my100servers
become: true
tasks:
- name: passwd change
user:
name: root
password: "{{ 'PLAIN_PASSWORD' | password_hash('sha512') }}"
Above playbook is well tested on linux systems.
$ ansible-playbook password-change.yaml
PLAY [my100servers] ***************************************************************************************
TASK [Gathering Facts] *******************************************************************************
ok: [server3]
ok: [server1]
ok: [server4]
ok: [server2]
ok: [server5]
.........................
TASK [passwd change] *********************************************************************************
<a href="ok: [server3]
ok: [server1]
ok: [server4]
ok: [server2]
ok: [server5]
.................">changed: [server3]
changed</a>: [server1]
<a href="ok: [server3]
ok: [server1]
ok: [server4]
ok: [server2]
ok: [server5]
.................">changed</a>: [server4]
<a href="ok: [server3]
ok: [server1]
ok: [server4]
ok: [server2]
ok: [server5]
.................">changed</a>: [server2]
<a href="ok: [server3]
ok: [server1]
ok: [server4]
ok: [server2]
ok: [server5]
.................">changed</a>: [server5]
..........................
PLAY RECAP *******************************************************************************************
server1 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
server2 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
server3 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
server4 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
server5 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
..........................