# Get item with file

**URL:** <https://forum.ansible.com/t/get-item-with-file/29818>\
**Category:** Ansible Project\
**Created:** [March 4, 2019, 12:24pm UTC](https://forum.ansible.com/t/get-item-with-file/29818 "2019-03-04T12:24:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [March 4, 2019, 12:24pm UTC](https://forum.ansible.com/t/get-item-with-file/29818/1 "2019-03-04T12:24:13Z")

</div>

Hy all,

I have one file with this content:

1,user1,host1,appli1  
2,user2,host2,appli2

3,user1,host1.appli3

This task works :

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

**- name: “Affichage de l’indice associe avec user et hostname”**  
**debug:**  
**var: indice**

BUT my variable indice get only indice **3** but indice must get 1 and 3.

How make for that my variable indice get 1,2 or [1,2]

my variable indice get only last line !

Thank you very much guy !!

Regards,

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [March 4, 2019, 3:28pm UTC](https://forum.ansible.com/t/get-item-with-file/29818/2 "2019-03-04T15:28:41Z")

</div>

> Hy all,
> 
> I have one file with this content:
> 
> 1,user1,host1,appli1  
> 2,user2,host2,appli2  
> 3,user1,host1.appli3
> 
> This task works :
> 
> \*- set\_fact:\*  
> \* indice: "{{ item.split(',')[0] }}"\*

Change this :

\* indice: "{{ item.split(',')[0] }}"\*

To something like this (not tested, but you should have the idea) :

\* indice: "{{ indice|default()|union(item.split(',')[0]) }}"\*

---

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [March 4, 2019, 3:55pm UTC](https://forum.ansible.com/t/get-item-with-file/29818/3 "2019-03-04T15:55:42Z")

</div>

Thanks for answer, for information i have this error :

fatal: [rebebsr6cweb01]: FAILED! =\> {“msg”: “Unexpected templating type error occurred on ({{ indice|default()|union(item.split(‘,’)[0]) }}): can only concatenate list (not "unicode") to list”}

Regards,

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [March 4, 2019, 3:59pm UTC](https://forum.ansible.com/t/get-item-with-file/29818/4 "2019-03-04T15:59:13Z")

</div>

Like as said not tested, try to learn a little bit by yourself... It's a string so you have to turn it into a list.

Try this (not tested again)\*

---

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [March 5, 2019, 10:37am UTC](https://forum.ansible.com/t/get-item-with-file/29818/5 "2019-03-05T10:37:29Z")

</div>

Hy Jean-Yves,

It’s works perfectly, you are the very the best i want become as you very !! 🙂

Thanks,

Regards
