Hello, why does short circuit only works for the first two cases:
- hosts: localhost
become: false
vars:
ivar: '{{hostvars[inventory_hostname].dne}}'
tasks:
- debug:
msg: "works: {{'foo' or dne}}"
- debug:
msg: "works: {{'bar' or hostvars[inventory_hostname].dne}}"
- debug:
msg: "fails: {{'baz' or ivar}}
The third debug will generate an error:
The task includes an option with an undefined variable.
The error was: {{hostvars[inventory_hostname].dne}}:
'ansible.vars.hostvars.HostVarsVars object' has no attribute 'dne'
Why is it even looking up in hostvars at all? The non-empty
string should evaluate True, so why is it reading the ORed
condition? The same thing happens with "if true else" and
ternary(true, ...) filter. It seems that it's properly
short-circuiting in the first two cases, because the variable
"dne" does not exist, and there is no error. Even more
confusing, the expansion of host vars is the exact same in cases
2 and 3, it's only going through an indirect variable in case 3.
This seems to happen regardless of the source of variables ie
extra vars, vars_files, etc.
Is this a bug, or what am I missing?