Example of using using module csv_to_facts:
---
- hosts: localhost
gather_facts: no
tasks:
- name: Get facts from CSV file
csv_to_facts:
src: '{{ playbook_dir }}/files/tu.csv'
table: endpoint
vsheets:
- EPinfo:
- tenant
- egp
- vrf
- name: map the variable names from dictionary
debug:
msg: "tenant {{ item.tenant }} epg {{ item.egp }} vrf {{ item.vrf }}"
with_items:
- "{{ endpoint }}"
Output
$ ansible-playbook tu.yml
PLAY [localhost] **************************************************************************************************************************
TASK [Get facts from CSV file] ************************************************************************************************************
ok: [localhost]
TASK [map the variable names from dictionary] *********************************************************************************************
ok: [localhost] => (item={u'egp': u'dev-epg', u'vrf': u'dev-vrf', u'tenant': u'dev'}) => {}
MSG:
tenant dev epg dev-epg vrf dev-vrf
ok: [localhost] => (item={u'egp': u'stg-epg', u'vrf': u'stg-vrf', u'tenant': u'stg'}) => {}
MSG:
tenant stg epg stg-epg vrf stg-vrf
PLAY RECAP ********************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0