Learning from a great answer to my question about how Ansible parses Booleans, I still don't understand why Ansible ends up evaluating the following condition as True
instead of False
:
Define two variables in an INI-format inventory:
a=false # parsed as 'unicode' (String)
b=True # parsed as 'bool'
Now testing some simple conditions:
- debug:
msg: "The variable 'a' is true!"
when: a
- debug:
msg: "The variable 'b' is true!"
when: b
- debug:
msg: "The variables 'a' and 'b' are both true!"
when: a and b
The result is that a
is false, b
is true, and interestingly a and b
is also true!
TASK [jenkins : debug] **********************************************************
skipping: [localhost] => {
"skip_reason": "Conditional result was False", "skipped": true
}
TASK [jenkins : debug] **********************************************************
ok: [localhost] => {
"msg": "The variable 'b' is true!"
}
TASK [jenkins : debug] **********************************************************
ok: [localhost] => {
"msg": "The variables 'a' and 'b' are both true!"
}
In an answer to this question the following is explained:
In python any non-empty string should be truthy. But when directly used in a condition it evaluates to false.
So this explains that when: a
evaluates to False, but it does not explain why when: a and b
evaluates to True.
It would be great if anybody could explain this outcome in detail.