Hi Ansible gurus,
I have a csv file with a list of hostnames and passwords
eg:
host1,password1
host2,password2
I can successfully read from that file using the read_csv module.
Now I’d like to use the “user” module to update the root password on each host defined in the CSV file. So I’ve got:
-
name: Bulk root password updater
hosts: {{ groups.infrastructure }}
become: yes
gather_facts: False
tasks: -
read_csv:
path: ./passtest.csv
fieldnames: hostname,password
delimiter: ‘,’
delegate_to: localhost
register: destpasswords -
debug:
var: destpasswords.list.0.hostname
var: destpasswords.list.0.password
msg: ‘{{destpasswords.list.0.value}}’
#Works up to this point, the debug above prints the first value from the file and correctly puts it into a variable. So now I want to use the user module to actually update the root passwords to whatever it reads from the file:
- name: Update root password to match what’s in CSV file
user:
name: root
update_password: always
password: “{{ destpasswords.list.hostname.password | password_hash(‘sha512’) }}”
loop: “{{destpasswords.list}}”
loop_control:
loop_var: hostname
However that doesn’t work. I’ve been able to update multiple hosts to the same root password(which is not what I want).
Any help much appreciated. I can do it a different way(ie. yaml instead of csv) if that’s easier.