issue when variable substitution using set command in jinja2 template

13 views
Skip to first unread message

Priyadarshini Venkatasamy

unread,
Jan 23, 2019, 4:25:26 AM1/23/19
to Ansible Project

I have a YAML file that has default value for two dict defined as follows:

sample:
  high:
    name: high-volume
    alias: hi-vl

hi-vl:
  ab1:    
    add:
      range: 0
      range1: 0
    remove:
      range: -1
      range1: -1
To iterate and get the values from jinja2 template i am using the code below:
{% for key, value in sample.iteritems() %}
{% set al = value.alias %}
{% for key1, value1 in al.iteritems()  %}

When I execute this template to generate the YAML file I get the error:

"msg": "AnsibleUndefinedVariable: 'unicode object' has no attribute 'iteritems'"}

The set variable is changing the variable as unicode. 

If I substitute the direct value instead of value.alias in the set statement the iteration works fine.

I tried using filters like to_yamltojson but they convert to string and not render as dict.

Has anyone faced this issue?


Reply all
Reply to author
Forward
0 new messages