# get indice in csv file

**URL:** <https://forum.ansible.com/t/get-indice-in-csv-file/31090>\
**Category:** Ansible Project\
**Created:** [August 21, 2019, 3:36pm UTC](https://forum.ansible.com/t/get-indice-in-csv-file/31090 "2019-08-21T15:36:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karther](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@Karther](https://forum.ansible.com/u/Karther)\
**Post date:** [August 21, 2019, 3:36pm UTC](https://forum.ansible.com/t/get-indice-in-csv-file/31090/1 "2019-08-21T15:36:58Z")

</div>

Hey,

I have on file csv “clef\_applicatives.csv” with this content :

13,my\_user,my\_host,gis  
14,my\_user,my\_host,gis

I have next tasks with this content :

- set\_fact:  
indice: “{{ item.split(‘,’)[0] }}”  
with\_lines: cat /home/ansible/test/test\_ssh\_manager/clef\_applicatives.csv  
when: item.split(‘,’)[2] == inventory\_hostname  
delegate\_to: localhost

- name: “Afficher indice”  
debug:  
msg: “{{ indice }}”

The problem is that my variable indice get only last indice of my file who is 14 and not 13.

How do for that ansible play playbook with this both values.  
(there is probabily other values in this file …)

Help me please community ansible !!!

Regards,

Karther

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [August 21, 2019, 4:29pm UTC](https://forum.ansible.com/t/get-indice-in-csv-file/31090/2 "2019-08-21T16:29:09Z")

</div>

Hi, add the items to the list in the loop

- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;indice: "{{ indice|default() + [item.split(',')[0]] }}"  
&nbsp;&nbsp;&nbsp;...

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Karther](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@Karther](https://forum.ansible.com/u/Karther)\
**Post date:** [August 22, 2019, 8:37am UTC](https://forum.ansible.com/t/get-indice-in-csv-file/31090/3 "2019-08-22T08:37:57Z")

</div>

Hey,

You are very the best !!! it’s works !!!

Thank you veryyyyy muchhhhhh !!! I love you !!! =)

Regards,
