get indice in csv file

12 views
Skip to first unread message

Karther

unread,
Aug 21, 2019, 11:36:58 AM8/21/19
to Ansible Project
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

Vladimir Botka

unread,
Aug 21, 2019, 12:29:21 PM8/21/19
to Karther, ansible...@googlegroups.com
Hi, add the items to the list in the loop

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

-vlado
--
Regards,
Vladimir

Vladimir Botka
vbo...@gmail.com
+420.773.041.182
Smeralova 13, Prague 17000, Czech
https://www.botka.link/
https://www.linkedin.com/in/vbotka/
--

Karther

unread,
Aug 22, 2019, 4:37:57 AM8/22/19
to Ansible Project
Hey,

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

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

Regards,
Reply all
Reply to author
Forward
0 new messages