Unable to get json/yaml file to parse appropriately in jinja2

14 views
Skip to first unread message

Bob Brown

unread,
May 19, 2016, 9:01:55 PM5/19/16
to Ansible Project
I have a structure that looks like this:

---
Volumes:
  - name:   data
    size:   80
    iops:   250
    device: /dev/xvdf
    type:   standard
    id:     vol-05778cd5

  - name:   journal
    size:   20
    iops:   250
    device: /dev/xvdg
    type:   standard
    id:     vol-59768d89

  - name:   log
    size:   10
    iops:   250
    device: /dev/xvdh
    type:   standard
    id:     vol-6f768dbf

I am creating a script using templating and a portion of that script will use the data structure above to attach the volumes and then mount them

So the output for the particular section should be something like

attachAndMount /data /dev/xvdf vol-5778cd5
attachAndMount /journal /dev/xvdg vol-59768d89
attachAndMount /log /dev/xvdh vol-6f768dbf


I'm trying to use:

{% for item in {{ Volumes }} %}
  attachAndMount {{ item.name }} {{ item.device }} {{ item.id }}
{% endfor %}

But getting errors that indicate that Volumes is the wrong type of data to use here.








Bob Brown

unread,
May 20, 2016, 12:35:17 AM5/20/16
to Ansible Project
Aha!  Thanks Benjamin for letting me know what's wrong.


{% for item in {{ Volumes }} %}

should be


{% for item in Volumes %}


Reply all
Reply to author
Forward
0 new messages