2

I'm wondering if it's possible to use a Jinja2 {% if %} expression inside a vars file?

So say I have:

az:
 az1: foo
 az2: bar
 az3: foobar

{% if az == az['az1'] %}
  floating_ip_pool = bar
{% endif %}

Basically, I'm trying to avoid having to set these variables each time since they'll always be based on the az.

Thanks.

nascarj
  • 23
  • 2

1 Answers1

3

That's not valid syntax. A vars file must first be parsed as a YAML document, and introducing that Jinja syntax results in something that is no longer valid YAML.

You can do something like this instead:

az:
 az1: foo
 az2: bar
 az3: foobar

floating_ip_pool: "{% if target_az == az['az1'] %}bar{% endif %}"
larsks
  • 277,717
  • 41
  • 399
  • 399