Experts Hi, 

I have couple of variable files like below:

$ cat vars_ip.yml
---
12.1.1.25: TAP1
12.1.1.26: TAP2
11.0.0.26: TAP3
11.0.0.27: TAP4
9.2.2.211: SAT1
9.2.2.212: SAT2
10.7.7.28: SAT3
10.7.7.29: SAT4
9.2.2.213: SAT5
10.7.7.30: SAT6


$ cat vars.yml

---
  layers:
    - name: MY_LAYER
      things_prod:
        - 12.1.1.25
        - 12.1.1.26
      things_dr:
        - 11.0.0.26
        - 11.0.0.27
      bgcolor:
        - '#AED6F1'


    - name: YR_LAYER
      things_prod:
        - 9.2.2.211
        - 9.2.2.212
        - 9.2.2.213
      things_dr:
        - 10.7.7.28
        - 10.7.7.29
        - 10.7.7.30
      bgcolor:
        - '#F9E79F'


Here is my playbook:

$ cat varloop.yml

---
  - name: Demonstrating variables in Jinja2 Loops
    hosts: localhost
    vars_files:
      - vars.yml
      - vars_ip.yml
    gather_facts: no
    tasks:
      - name: Create the Jinja2 based templateone
        template: src=./varloop.j2 dest=./sync/sync.html


Here is my Jinja template file:

$ cat varloop.j2


{% for layer in layers %}
{% for item in layer.things_prod %}
{{ item }} {{ layer.things_dr[loop.index-1] }} var[{{ item }}] var[layer.
things_dr[loop.index-1]]
{% endfor %}
{% endfor %}


$ cat ./sync/sync.html
Output:

Current Output:
$ cat ./sync/sync.html


12.1.1.25 11.0.0.26 var[12.1.1.25] var[layer.things_dr[loop.index-1]]
12.1.1.26 11.0.0.27 var[12.1.1.26] var[layer.things_dr[loop.index-1]]
9.2.2.211 10.7.7.28 var[9.2.2.211] var[layer.things_dr[loop.index-1]]
9.2.2.212 10.7.7.29 var[9.2.2.212] var[layer.things_dr[loop.index-1]]
9.2.2.213 10.7.7.30 var[9.2.2.213] var[layer.things_dr[loop.index-1]]


I need the values from the vars_ip.yml variable file to be populated in the 
jinja template like below:

Expected output:
12.1.1.25 11.0.0.26 TAP1 TAP3
12.1.1.26 11.0.0.27 TAP2 TAP4
9.2.2.211 10.7.7.28 WAS1 WAS3
9.2.2.212 10.7.7.29 WAS2 TAP4
9.2.2.213 10.7.7.30 WAS3 WAS6

 Kindly suggests.





-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6fd3c5d7-2460-4afa-b9ad-22e5dfb19a57%40googlegroups.com.

Reply via email to