I am new to ansible , looking to see if I can import variables from csv file and either build an inventory file or use them in a playbook , Appreciate your feedback.
root@ansibile-launch:~/ansible/tasks/csv-file# cat test2.yml
---
- hosts: localhost
connection: local
become: false
tasks:
- name: efine Values From CSV File
set_fact:
tenant: "{{ lookup('csvfile', ' file=/root/ansible/tasks/csv-file/example.csv delimiter=, col=1') }}
debug:
msg: " Print tenant {{tenant}}"
delegate_to: localhost
root@ansibile-launch:~/ansible/tasks/csv-file# cat example.csv
tenant-name,vrf-name,app-name,bd-name,bd-subnet,epg-name,vlan-id,status_is
root@ansibile-launch:~/ansible/tasks/csv-file# ansible-playbook test2.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
ERROR! Syntax Error while loading YAML.
did not find expected key
The error appears to have been in '/root/ansible/tasks/csv-file/test2.yml': line 11, column 14, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
debug:
msg: " Print tenant {{tenant}}"
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"