# How to iterate over nested lists with lineinfile?

**URL:** <https://forum.ansible.com/t/how-to-iterate-over-nested-lists-with-lineinfile/19347>\
**Category:** Ansible Project\
**Created:** [September 23, 2015, 6:48pm UTC](https://forum.ansible.com/t/how-to-iterate-over-nested-lists-with-lineinfile/19347 "2015-09-23T18:48:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [September 23, 2015, 6:48pm UTC](https://forum.ansible.com/t/how-to-iterate-over-nested-lists-with-lineinfile/19347/1 "2015-09-23T18:48:50Z")

</div>

I am trying to build a hash of users from a csv file. I am stuck on this last step, where the playbook just hangs:

- name: print user details into hash  
lineinfile: ‘dest=~csit-ansible/files/auto\_students.yml  
line=“{{ item }}”  
state=present’  
with\_items:
- " username: {{ item[0] }}"
- " firstname: {{ item[1] }}"
- " lastname: {{ item[2] }}"
- " studentid: {{ item[3] }}"
- " dob: {{ item[4] }}"  
with\_nested:
- “{{ usernames.stdout\_lines }}”
- “{{ firstnames.stdout\_lines }}”
- “{{ lastnames.stdout\_lines }}”
- “{{ studentids.stdout\_lines }}”
- “{{ dobs.stdout\_lines }}”

Earlier in the playbook, I register the values like so:

- name: print all usernames to stdout  
shell: awk -F ‘:’ ‘{print $1}’ ~csit-ansible/files/sortedu${date}.csv  
register: usernames

- name: print all firstnames to stdout  
shell: awk -F ‘:’ ‘{print $2}’ ~csit-ansible/files/sortedu${date}.csv  
register: firstnames

- name: print all lastnames to stdout  
shell: awk -F ‘:’ ‘{print $3}’ ~csit-ansible/files/sortedu${date}.csv  
register: lastnames

- name: print all studentids to stdout  
shell: awk -F ‘:’ ‘{print $4}’ ~csit-ansible/files/sortedu${date}.csv  
register: studentids

- name: print all dobs to stdout  
shell: awk -F ‘:’ ‘{print $5}’ ~csit-ansible/files/sortedu${date}.csv  
register: dobs

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [September 24, 2015, 4:57pm UTC](https://forum.ansible.com/t/how-to-iterate-over-nested-lists-with-lineinfile/19347/2 "2015-09-24T16:57:25Z")

</div>

I ended up learning a little python3 so I could use it to generate the dictionary for me.
