Problem with get indice in file

18 views
Skip to first unread message

Karther

unread,
Aug 20, 2019, 8:39:45 AM8/20/19
to Ansible Project
Hey !

I have strange problem :

I have on file "clef_applicatives.csv" with this content :

2,user1,host1,clef1
7,user3,host2,clef5
6,user4,host4,clef6
42,user5,host5,clef7
23,user6,host8,clef8
3,user7,host3,clef9
22,user8,host10,clef14
20,user9,host7,clef11

I have on task who get indice depending on the host.

- set_fact:
      indice: "{{ indice|default([])|union(item.split(',')[0]|list) }}"
  with_lines: cat /home/ansible/ssh_manager/clef_applicatives.csv
  when: item.split(',')[2] == inventory_hostname
  delegate_to: localhost

My problem is that this task works perfectly but when i use indice "22" in my file "clef_applicatives.csv", my variable indice get only 2 and not 22 same if my host is my inventory_hostname ....

Someone can help me please !!!!??? :)

I'm desesper !!!

Thanks community ansible !!!! :)

Regards,

Karther

unread,
Aug 20, 2019, 9:02:31 AM8/20/19
to Ansible Project
Hey,

Update.

The problem is that when i use number with same caractere exemple "11, 22, 33, 44, 55 , etc ..."
This task get only the first caracter "1 or 2 or 3 or 4 , etc..."

Thanks,
Regards,

Dick Visser

unread,
Aug 20, 2019, 9:29:55 AM8/20/19
to ansible...@googlegroups.com
Hi



On Tue, 20 Aug 2019 at 14:39, Karther <ryadmo...@gmail.com> wrote:
> - set_fact:
> indice: "{{ indice|default([])|union(item.split(',')[0]|list) }}"
> with_lines: cat /home/ansible/ssh_manager/clef_applicatives.csv
> when: item.split(',')[2] == inventory_hostname

Stop doing that.
There is a dedicated module to handle csv files:

https://docs.ansible.com/ansible/latest/modules/read_csv_module.html



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Karther

unread,
Aug 20, 2019, 9:49:47 AM8/20/19
to Ansible Project
Hey,

This module not work !! :/

I have error synthax i don't understand why !! :/

Can you help me for my first message please with this task :

- set_fact:
      indice: "{{ indice|default([])|union(item.split(',')[0]|list) }}"
  with_lines: cat /home/ansible/ssh_manager/clef_applicatives.csv
  when: item.split(',')[2] == inventory_hostname
  delegate_to: localhost

Thanks you very much Community Ansible !!! :)

Regards,

Karther

unread,
Aug 20, 2019, 10:32:09 AM8/20/19
to Ansible Project
Hey,

Help me please !!! :)

If i change this task with lookup, i will be to change my whole program !!! ;(

Regards,
Reply all
Reply to author
Forward
0 new messages