Ansible warning on jinja2 braces on when -
i using code in vars
my_var: "{{lookup('env','my_var') | default(true, true)}}"
i using like
- include: task.yml when: my_var
this worked without issue in ansible 2.2
in ansible 2.3 warning this
[warning]: when statements should not include jinja2 templating delimiters such {{ }} or {% %}. found: {{lookup('env','my_var') | default(true, true)}}
so if use my_var: "lookup('env','my_var') | default(true, true)"
, mean remove {{ }}
, no warning my_var
evaluated true no matter if pass false env variable. works fine in previous code gave
how can fix it?
the cleanest way set fact instead of using template in variable (it prevent lookup plugin being called multiple times in included tasks - not huge performance gain, cleaner):
- set_fact: my_var: "{{lookup('env','my_var') | default(true, true)}}"
also mind evaluate true
in cases when environment my_var
different false
.
if [ ] remove
{{ }}
no warningmy_var
evaluated true
because considered string , non-empty string value evaluates true
(with exception of string value equal false
).
Comments
Post a Comment