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?