Re: [ansible-project] lookup csvfile with_items issue

2015-07-08 Thread Bart Pit
Any ideas on the 

delimiter must be string, not unicode

error?


Op dinsdag 7 juli 2015 23:55:34 UTC+2 schreef Bart Pit:

 For extra clarification: I started getting this error without the quotes 
 around the comma. So like this, produces the same error:

 debug: msg={{ lookup('csvfile', item + ' file=test.csv delimiter=, 
 col=2') }}


 Op dinsdag 7 juli 2015 22:57:47 UTC+2 schreef Bart Pit:

 Thanks Brian! It doing something more now, that's good :)

 However, I now get this error:

 fatal: [localhost] = Failed to template msg={{ lookup('csvfile', item 
 + ' file=test.csv delimiter=, col=2') }}: csvfile: delimiter must 
 be string, not unicode

 I tried quoting the comma, double and single. And tried the approach in 
 this thread, both single and double: 
 https://groups.google.com/forum/#!topic/ansible-project/r2L3UONwaN0 like 
 so:

 debug: msg={{ lookup('csvfile', item + ' file=test.csv delimiter=',' 
 col=2') }}

 But also doesn't work.

 Any ideas?



 Op dinsdag 7 juli 2015 22:23:18 UTC+2 schreef Brian Coca:

 you are forcing item to be a static string, it needs to be like this: 

 - name: read from csv file 
   debug: msg={{ lookup('csvfile', item + ' file=/path/to/file.csv 
 delimiter=, col=1') }} 
   with_items: test_ids 

 -- 
 Brian Coca 



-- 
You received this message because you are subscribed to the Google Groups 
Ansible Project group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/51dd1fdf-4985-49b9-adb9-e0b3b49d7dc4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] lookup csvfile with_items issue

2015-07-07 Thread Bart Pit
Hi! I'm struggling to get 'lookup' with 'csvfile' in combination with 
'with_items' to work.

I have this csv file (shortened snippet):

col1,col2
1,Mike
2,Sally

Than I also have this var:

test_ids:
  - 1
  - 2

Now I want to lookup (docs: 
https://docs.ansible.com/playbooks_lookups.html#the-csv-file-lookup) the 
values in the second column of the csv file:

- name: read from csv file
  debug: msg={{ lookup('csvfile', 'item file=/path/to/file.csv delimiter=, 
col=1') }}
  with_items: test_ids

Where 'item' before file=/... should output 1 and 2 right??

This doesn't work, output is:

TASK: [client-setup | read from csv file] 
ok: [localhost] = (item=1) = {
item: 1,
msg: []
}
ok: [localhost] = (item=2) = {
item: 2,
msg: []
}

As you can see it recognizes 1 and 2, but I don't get the values of the 
second column in the csv.

If I hardcode the number in like so:

- name: read from csv file
  debug: msg={{ lookup('csvfile', '1 file=test.csv delimiter=, col=1') }}
  with_items: test_ids


It does give me the correct result:

TASK: [client-setup | read from csv file] 
ok: [localhost] = (item=1) = {
item: 1,
msg: Mike
}
ok: [localhost] = (item=2) = {
item: 2,
msg: Mike
}

I tried quoting the var with '1' and '2', but that doesn't work either.

Is this a bug or am I doing something wrong?

-- 
You received this message because you are subscribed to the Google Groups 
Ansible Project group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4d6c6057-b0a5-4ed4-91f1-ac179f99655f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] lookup csvfile with_items issue

2015-07-07 Thread Brian Coca
you are forcing item to be a static string, it needs to be like this:

- name: read from csv file
  debug: msg={{ lookup('csvfile', item + ' file=/path/to/file.csv
delimiter=, col=1') }}
  with_items: test_ids

-- 
Brian Coca

-- 
You received this message because you are subscribed to the Google Groups 
Ansible Project group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAJ5XC8kA-VLXAuQ9F5VH5L8CnCk0rkQowFtcHD2fW9Nju6-9qg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] lookup csvfile with_items issue

2015-07-07 Thread Bart Pit
For extra clarification: I started getting this error without the quotes 
around the comma. So like this, produces the same error:

debug: msg={{ lookup('csvfile', item + ' file=test.csv delimiter=, col=2') 
}}


Op dinsdag 7 juli 2015 22:57:47 UTC+2 schreef Bart Pit:

 Thanks Brian! It doing something more now, that's good :)

 However, I now get this error:

 fatal: [localhost] = Failed to template msg={{ lookup('csvfile', item + 
 ' file=test.csv delimiter=, col=2') }}: csvfile: delimiter must be 
 string, not unicode

 I tried quoting the comma, double and single. And tried the approach in 
 this thread, both single and double: 
 https://groups.google.com/forum/#!topic/ansible-project/r2L3UONwaN0 like 
 so:

 debug: msg={{ lookup('csvfile', item + ' file=test.csv delimiter=',' 
 col=2') }}

 But also doesn't work.

 Any ideas?



 Op dinsdag 7 juli 2015 22:23:18 UTC+2 schreef Brian Coca:

 you are forcing item to be a static string, it needs to be like this: 

 - name: read from csv file 
   debug: msg={{ lookup('csvfile', item + ' file=/path/to/file.csv 
 delimiter=, col=1') }} 
   with_items: test_ids 

 -- 
 Brian Coca 



-- 
You received this message because you are subscribed to the Google Groups 
Ansible Project group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2a8ec8d9-a545-4ac6-8192-a7eb638ea8c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] lookup csvfile with_items issue

2015-07-07 Thread Bart Pit
Thanks Brian! It doing something more now, that's good :)

However, I now get this error:

fatal: [localhost] = Failed to template msg={{ lookup('csvfile', item + ' 
file=test.csv delimiter=, col=2') }}: csvfile: delimiter must be string
, not unicode

I tried quoting the comma, double and single. And tried the approach in 
this thread, both single and 
double: https://groups.google.com/forum/#!topic/ansible-project/r2L3UONwaN0 
like so:

debug: msg={{ lookup('csvfile', item + ' file=test.csv delimiter=',' 
col=2') }}

But also doesn't work.

Any ideas?



Op dinsdag 7 juli 2015 22:23:18 UTC+2 schreef Brian Coca:

 you are forcing item to be a static string, it needs to be like this: 

 - name: read from csv file 
   debug: msg={{ lookup('csvfile', item + ' file=/path/to/file.csv 
 delimiter=, col=1') }} 
   with_items: test_ids 

 -- 
 Brian Coca 


-- 
You received this message because you are subscribed to the Google Groups 
Ansible Project group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a5a39b91-5c6d-4b82-9766-4da3d6aa1639%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.