---
# Script to change password of a user on a set of servers
#
# Examples to run the script for servers into targethost section of hosts-xxx file:
# ansible-playbook change_password.yml -i hosts-xxx -e 'target=targethost my_remote_user=<your_remote_user> user_to_update=<login_of_user> password=<new_password>'
# ansible-playbook change_password.yml -i hosts-xxx -e 'target=targethost my_remote_user=<your_remote_user> user_to_update=<login_of_user> password=<new_password>' --limit=*.mydomain.com
#

- name: Playbook to change password on servers for a user
  hosts: '{{target}}'
  become: yes
  remote_user: "{{ my_remote_user }}"

  tasks:
  - name: Change password
    user:
      user: "{{ user_to_update }}"
      password: "{{ password |password_hash('sha512', 'mysalt') }}"
