On 2/3/14, 4:32 PM, Roman Revyakin wrote:
cat > test_playbook.yaml <<EOF
---
- hosts: all
gather_facts: false
tasks:
- name: Play only if var1 is true and var2 is defined
local_action: command echo "Yes {{ var1 }} is true and {{ var2 }}
is defined"
when: var1 and var2 is defined
EOF
$ ansible-playbook -i host -v test_playbook.yaml --extra-vars
"var1=false var2='something'"
PLAY [all]
********************************************************************
TASK: [Play only if var1 is true and var2 is defined]
*************************
changed: [localhost] => {"changed": true, "cmd": ["echo", "Yes false is
true and something is defined"], "delta": "0:00:00.003256", "end":
"2014-02-04 11:19:56.720699", "rc": 0, "start": "2014-02-04
11:19:56.717443", "stderr": "", "stdout": "Yes false is true and
something is defined"}
You most certainly have a string to bool comparison issue going on.
You can change this by using the bool filter.
when: var1|bool and var2 is defined
When I use this, var1 being "false" will still cause the task to be
skipped as expected.
-jlk
--
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 [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.