user3214546
user3214546

Reputation: 6831

How can I use default with variable in Ansible?

I know that I can use a simple hardcoded string in default but I am trying to do this:

myvar: "{{ lookup('env','var1') | default("{{var2}}",true) }}"

But it adds that as a string instead of evaluating it.

Upvotes: 1

Views: 1332

Answers (1)

techraf
techraf

Reputation: 68629

Once you opened a Jinja2 expression with {{ you don't need to open it again (especially quoted) and you can refer to the variables by their names:

myvar: "{{ lookup('env','var1') | default(var2, true) }}"

Upvotes: 3

Related Questions