Hi there ,
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.
Basic playbook I tried:
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
tenant_telstra_tenant,vrf_tenant,anp_tenant,bd_net2,
172.16.2.252/24,epg_net2,2102,"created,modified"
tenant_telstra_tenant,vrf_tenant,anp_tenant,bd_net3,
172.16.3.252/24,epg_net3,2103,"created,modified"
tenant_telstra_tenant,vrf_tenant,anp_tenant,bd_net4,
172.16.4.252/24,epg_net4,2104,"created,modified"
Error I am getting
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 }}"
Regards,
AR
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAL7z%3DgdUPwOg9qUOu_-33T4-Su48riSYwn8fnZTipodDUbG7tg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.