get indice in csv file

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

Hi, add the items to the list in the loop

- set_fact:
     indice: "{{ indice|default() + [item.split(',')[0]] }}"
   ...

  -vlado

Hey,

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

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

Regards,