strange jinja logic

29 views
Skip to first unread message

Barry Kaplan

unread,
Jul 17, 2015, 1:23:33 AM7/17/15
to ansible...@googlegroups.com
I have:

- debug: var=_consul_install_agent
- debug: var=consul_use_dnsmasq
- debug: msg="{{_consul_install_agent and consul_use_dnsmasq}}"


The two variables are true and false respectively, but the expression evaluates to true? 


TASK: [consul | debug var=_consul_install_agent] ******************************
ok
: [10.0.196.112] => {
   
"var": {
       
"_consul_install_agent": "False"
   
}
}


TASK
: [consul | debug var=consul_use_dnsmasq] *********************************
ok
: [10.0.196.112] => {
   
"var": {
       
"consul_use_dnsmasq": "True"
   
}
}


TASK
: [consul | debug msg="{{_consul_install_agent and consul_use_dnsmasq}}"] ***
ok
: [10.0.196.112] => {
   
"msg": "True"
}


But if the expression is 

- debug: msg="{{_consul_install_agent == true and consul_use_dnsmasq == true}}"

Then it evals to false.

Is this expected with jinja? Without the 'and' the '== true' seems not necessary.

Gerard Lynch

unread,
Jul 17, 2015, 7:37:32 AM7/17/15
to ansible...@googlegroups.com
There's a high likelihood that their type is actually 'string' instead of boolean, try

- debug: msg="{{ (_consul_install_agent | bool)  and (consult_use_dnsmasq | bool) }}"

Barry Kaplan

unread,
Jul 17, 2015, 10:58:08 PM7/17/15
to ansible...@googlegroups.com


On Friday, July 17, 2015 at 5:07:32 PM UTC+5:30, Gerard Lynch wrote:
There's a high likelihood that their type is actually 'string' instead of boolean, try


Indeed. The values were "== 'True'" not "== True". Thanks! 
Reply all
Reply to author
Forward
0 new messages