My Ansible conditional statements are not evaluating correctly.
- name: A
shell:
cmd: /usr/local/bin/is_A_OK #returns bash true or false (not strings)
register: is_A_OK
- name: B
shell:
cmd: /usr/local/bin/is_B_OK
register: is_B_OK
- name: reboot if both are OK
reboot:
when:
- is_A_OK
- is_B_OK
[DEPRECATION WARNING]: evaluating 'is_A_ok' as a bare variable, this behaviour will go away and you might need to add |bool to the expression in the future. Also see CONDITIONAL_BARE_VARS configuration toggle. This feature will be removed in version 2.12.
However, the logic works correctly, and the reboot is performed when both variables are true. But I can't leave it as-is given that this feature will be removed in version 2.12.
FYI, the bash scripts conclude like this:
if [[ "$my_var" == true ]]; then
true
else
false
fi
I'm running Arch Linux, so bash is new.
The warning plus the ansible docs made me think this would be correct:
- name: reboot if OK
reboot:
when:
- is_A_OK|bool
- is_B_OK|bool
The warning goes away, but the reboot is not preformed, even when both variables are true. I guess I don't understand the docs. (I'm new to Ansible.)
I found this question, but it is not relevant: Ansible conditional statements not evaluating correctly - Stack Overflow Ansible conditional statements not evaluating correctly
What am I doing wrong and not understanding?