Boolean variables and when condition

Hi guys,

Simple question … given that the vars below are boolean type with values of true or false, does this condition make sense?

when: (var1 | bool and var2 | bool) or not var3 | bool

Although I would expect to work (based on what I can see in jinja2 reference) I’m not seeing the desired result so hence the question.

Thanks

If they are actual booleans already (and not a string value like ‘yes’ ‘no’ or ‘true’) then you don’t need to use the bool filter at all and it can be simplified to:

when: var1 and var2 or not var3

Regarding the logic, what does debug say the variable values are before the task you’re using them in with the when statement above?

Just skimming quickly it seems like you might wish to (var 3 | bool) and add some parens

However, really all this casting is almost always unneccessary if you just use YAML true/false in the variables files.

Thanks guys for looking into it. With some debugging it came up that one of the variables was never set and was always false, so another case of stupid user error. Otherwise can confirm that the condition works as expected with or without |bool, which I guess has higher importance when used with vars as {{ var | bool }} format.