Discussion:
[ansible-project] strange jinja logic
Barry Kaplan
2015-07-17 05:23:33 UTC
Permalink
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.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e8cca6bc-2658-4483-80e7-5fa179dfc5aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Gerard Lynch
2015-07-17 11:37:32 UTC
Permalink
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) }}"
Post by Barry Kaplan
- 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.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8b16891e-c797-41b0-91ad-8835d3862422%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Barry Kaplan
2015-07-18 02:58:08 UTC
Permalink
Post by Gerard Lynch
There's a high likelihood that their type is actually 'string' instead of
boolean, try
Indeed. The values were "== *'*True*'*" not "== True". Thanks!
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b208941d-997d-462b-8e81-bf894e499953%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...