Skip to content

Instantly share code, notes, and snippets.

@joelwking
Created July 25, 2019 22:30
Show Gist options
  • Save joelwking/0d911a99e3d1e7da0532447794bec35f to your computer and use it in GitHub Desktop.
Save joelwking/0d911a99e3d1e7da0532447794bec35f to your computer and use it in GitHub Desktop.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment