# Would like to update root passwords using user module, but have a different passwords for each VM and read those from a csv file

**URL:** <https://forum.ansible.com/t/would-like-to-update-root-passwords-using-user-module-but-have-a-different-passwords-for-each-vm-and-read-those-from-a-csv-file/33421>\
**Category:** Ansible Project\
**Created:** [July 16, 2020, 11:13pm UTC](https://forum.ansible.com/t/would-like-to-update-root-passwords-using-user-module-but-have-a-different-passwords-for-each-vm-and-read-those-from-a-csv-file/33421 "2020-07-16T23:13:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tibor\_I](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@Tibor\_I](https://forum.ansible.com/u/Tibor_I)\
**Post date:** [July 16, 2020, 11:13pm UTC](https://forum.ansible.com/t/would-like-to-update-root-passwords-using-user-module-but-have-a-different-passwords-for-each-vm-and-read-those-from-a-csv-file/33421/1 "2020-07-16T23:13:10Z")

</div>

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.
