Ansible to change user password

One 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] *********************************************************************************
changed: [server3]
changed: [server1]
changed: [server4]
changed: [server2]
changed: [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 
..........................