Pre req is to install passlib as Ansible doesn’t allow a cleartext password to e passed through the User module:

pip install passlib

Play book to update the username dave:

---
- hosts: all
  become: yes
  tasks:
    - name: Change user password
      user:
        name: dave
        update_password: always
        password: "{{ newpassword|password_hash('sha512') }}"

Run the playbook:

ansible-playbook -i hostfile change-password.yml --extra-vars newpassword=imanewpassword
Written by Matt Cooper
Hi, I'm Matt Cooper. I started this blog to pretty much act as a brain dump area for things I learn from day to day. You can contact me at: matt@linuxtutorial.co.uk.