Unable to print include_vars dictionary & list variables

13 views
Skip to first unread message

Shifa Shaikh

unread,
Mar 24, 2020, 7:22:47 AM3/24/20
to Ansible Project
Below is my playbook that loads and prints the variables

---
 
- name: Demonstrating variables in Jinja2 Loops
    hosts
: localhost


     
- name: Load variable files
        include_vars
:
          file
="{{ playbook_dir }}/vars/vars.yml"


     
- debug:
          msg
: "COUNTRY {{ item.countries | join('') }} has IP ADDRESS {{ item.1 | join('') }} which has DISKs {{ item.1.disks | join('') }}"
        with_subelements
:
         
- "{{ regions }}"
         
- countries.ALL_IPS



I wish to print like below for all the entries in the vars.yml

COUNTRY CORE DUBAI has IP ADDRESS 10.0.0.1 which has DISKS /fins and /tmp
COUNTRY CORE DUBAI has IP ADDRESS
10.0.0.4 has DISKS /was
COUNTRY CORE SINGAPORE has IP ADDRESS
10.0.1.5 which has DISKS /fins and /tmp


Below is my vars/vars.yml which is designed and works fine with my jinja2 template where i am able to fetch all value i need from vars.yml

---
  regions
:


   
- name: PROD
      countries
:
       
- CORE DUBAI:
          name
: CORE DUBAI
          ALL_IPS
:
               
- 10.0.0.1:
                  name
: 10.0.0.1
                  disks
:
                   
- /fins
                    - /
tmp
               
- 10.0.0.4:
                  name
: 10.0.0.4
                  disks
:
                   
- /was


        - CORE SINGAPORE:
          name: CORE SINGAPORE
          ALL_IPS:
                - 10.0.1.5:
                  name: 10.0.1.5
                  disks:
                    - /
fins
                   
- /tmp


I get the below error while running my playbook:

TASK [debug] ************************************************************************************************************************************************
fatal
: [localhost]: FAILED! => {"msg": "the key countries should point to a dictionary, got '[{u'ALL_IPS': [{u'disks': [u'/fins', u'/tmp'], u'10.0.0.1': None, u'name': u'10.0.0.1'}, {u'10.0.0.4': None, u'disks': [u'/was'], u'name': u'10.0.0.4'}], u'name': u'fins CORE DUBAI', u'fins CORE DUBAI': None}, {u'ALL_IPS': [{u'disks': [u'/fins', u'/tmp'], u'name': u'10.0.1.5', u'10.0.1.5': None}, {u'10.0.0.4': None, u'disks': [u'/was'], u'name': u'10.0.0.4'}], u'fins CORE SINGAPORE': None, u'name': u'fins CORE SINGAPORE'}]'"}


PLAY RECAP
**************************************************************************************************************************************************
localhost                  
: ok=2    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0


Can you please suggest how can i get the desired output ?
Reply all
Reply to author
Forward
0 new messages