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 warning my_var evaluated true

because considered string , non-empty string value evaluates true (with exception of string value equal false).


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -