HI,
I find Ansible docs really frustrating. Never a full example that is not trivial or misleading.
Please, can someone provide a working example of a play to iterate over the rows of a csvfile?
Thanks.
HI,
I find Ansible docs really frustrating. Never a full example that is not trivial or misleading.
Please, can someone provide a working example of a play to iterate over the rows of a csvfile?
Thanks.
there are plenty of specific examples, just your specific case is not
covered, but it is simple enough to inffer from existing ones,
something like this should work:
- name: show the row
debug: var=item
loop: " {{ lookup('file', '/path/tocsv') }}"
you might need to split on ',' if you want the columns, there is a
csvfile lookup it it retrieves specific column, not rows
Sorry, but it’s not clear at all how debug iterates over the rows.
Running a simple debug doesn’t help.
For example, if I had a playbook like this (that of course doesn’t work), how should I fix it
to iterate over every single row and print the value of the 3 columns?
Hi Nico,
Not sure if this is what you are looking for but for a sample CSV file
`
host, user, password, comment,
1.1.1.1, claudia, mypassword, the first one
1.1.1.2, elvira, epassword, the second one
1.1.1.3, billy, bpassword, the third one
`
with this playbook sample_csv.yml
`
Take a look at csv_to_facts module
I found this to be quick and dirty way to access data from a spreadsheet → converted to csv first. Look inside the .py for extra info on how to use it.
Oh, and you can drop the csv_to_facgts.py in ./library in your project folder…your playbook should then be able to use the module.
`