Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

ansible-playbook, when

ANSIBLE VERSION

ansible 2.2.1.0
config file = /home/skazi/.ansible.cfg
configured module search path = Default w/o overrides

CONFIGURATION

[defaults]
inventory = $HOME/ansible/hosts

gathering = smart
fact_caching = jsonfile
fact_caching_connection = $HOME/.ansible/facts_cache
fact_caching_timeout = 86400

[privilege_escalation]
become=True
become_method=sudo
become_user=root
#become_ask_pass=True

OS / ENVIRONMENT

Debian Jessie

SUMMARY

Conditions using boolean variables and and are not evaluated correctly when variable values are changed from outside the playbook.

The when: ansible_distribution == "Debian" and bool_test expression is correctly evaluated when bool_test is changed inside the playbook but not if it's changed when including playbook in another one or with --extra-vars CLI parameter. The list version of and works correctly.

STEPS TO REPRODUCE

test.yaml

---
- hosts: all
vars:
bool_test: True
tasks:
- debug: "msg={{ bool_test }}"

- name: Run when distro and test list
debug: "msg='true so running'"
when:
- ansible_distribution == "Debian"
- bool_test

- name: Run when distro and test
debug: "msg='true so running'"
when: ansible_distribution == "Debian" and bool_test

- name: Run when distro
debug: "msg='true so running'"
when: ansible_distribution == "Debian"

- name: Run when test
debug: "msg='true so running'"
when: bool_test

test2.yml

---
- include: test.yml bool_test=False
- include: test.yml bool_test=True

shell

$ ansible-playbook test.yml --limit localhost
$ ansible-playbook test.yml --limit localhost --extra-vars bool_test=False
$ ansible-playbook test2.yml --limit localhost

EXPECTED RESULTS

$ ansible-playbook test.yml --limit localhost

PLAY [all] *********************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": true
}

TASK [Run when distro and test list] *******************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when distro and test] ************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when distro] *********************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when test] ***********************************************************
ok: [localhost] => {
"msg": "true so running"
}

PLAY RECAP *********************************************************************
localhost : ok=5 changed=0 unreachable=0 failed=0

$ ansible-playbook test.yml --limit localhost --extra-vars bool_test=False

PLAY [all] *********************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": false
}

TASK [Run when distro and test list] *******************************************
skipping: [localhost]

TASK [Run when distro and test] ************************************************
skipping: [localhost]

TASK [Run when distro] *********************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when test] ***********************************************************
skipping: [localhost]

PLAY RECAP *********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0

$ ansible-playbook test2.yml --limit localhost

PLAY [all] *********************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": false
}

TASK [Run when distro and test list] *******************************************
skipping: [localhost]

TASK [Run when distro and test] ************************************************
skipping: [localhost]

TASK [Run when distro] *********************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when test] ***********************************************************
skipping: [localhost]

PLAY [all] *********************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": true
}

TASK [Run when distro and test list] *******************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when distro and test] ************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when distro] *********************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when test] ***********************************************************
ok: [localhost] => {
"msg": "true so running"
}

PLAY RECAP *********************************************************************
localhost : ok=8 changed=0 unreachable=0 failed=0

ACTUAL RESULTS

$ ansible-playbook test.yml --limit localhost

PLAY [all] *********************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": true
}

TASK [Run when distro and test list] *******************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when distro and test] ************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when distro] *********************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when test] ***********************************************************
ok: [localhost] => {
"msg": "true so running"
}

PLAY RECAP *********************************************************************
localhost : ok=5 changed=0 unreachable=0 failed=0

$ ansible-playbook test.yml --limit localhost --extra-vars bool_test=False

PLAY [all] *********************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": false
}

TASK [Run when distro and test list] *******************************************
skipping: [localhost]

TASK [Run when distro and test] ************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when distro] *********************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when test] ***********************************************************
skipping: [localhost]

PLAY RECAP *********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0

$ ansible-playbook test2.yml --limit localhost

PLAY [all] *********************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": false
}

TASK [Run when distro and test list] *******************************************
skipping: [localhost]

TASK [Run when distro and test] ************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when distro] *********************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when test] ***********************************************************
skipping: [localhost]

PLAY [all] *********************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": true
}

TASK [Run when distro and test list] *******************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when distro and test] ************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when distro] *********************************************************
ok: [localhost] => {
"msg": "true so running"
}

TASK [Run when test] ***********************************************************
ok: [localhost] => {
"msg": "true so running"
}

PLAY RECAP *********************************************************************
localhost : ok=8 changed=0 unreachable=0 failed=0

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

extra-vars

when

ANSIBLE VERSION

ansible 2.1.1.0

CONFIGURATION

OS / ENVIRONMENT

Darwin alfheim.local 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64

SUMMARY

Unable to pass boolean variable False via --extra-vars arguments

STEPS TO REPRODUCE

cat test.yml

- hosts: localhost
vars:
- foobar: True
tasks:
- debug: var=foobar

- debug: var=foobar
when: not foobar

- debug: var=foobar
when: foobar

- hosts: localhost
vars:
- foobar: False
tasks:
- debug: var=foobar

- debug: var=foobar
when: not foobar

- debug: var=foobar
when: foobar

EXPECTED RESULTS

Running playbook without passing extra-vars to override foobar variable works as expected.

ansible-playbook -i inventory test.yml

PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
"foobar": true
}

TASK [debug] *******************************************************************
skipping: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
"foobar": true
}

PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
"foobar": false
}

TASK [debug] *******************************************************************
ok: [localhost] => {
"foobar": false
}

TASK [debug] *******************************************************************
skipping: [localhost]

PLAY RECAP *********************************************************************
localhost : ok=6 changed=0 unreachable=0 failed=0

Running playbook with passing foobar=True as extra-vars parameter works as expected.

ansible-playbook -i inventory test.yml -e foobar=True

PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
"foobar": true
}

TASK [debug] *******************************************************************
skipping: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
"foobar": true
}

PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
"foobar": true
}

TASK [debug] *******************************************************************
skipping: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
"foobar": true
}

PLAY RECAP *********************************************************************
localhost : ok=6 changed=0 unreachable=0 failed=0

ACTUAL RESULTS

Running playbook with passing foobar=False as extra-vars parameter does not work as expected. Both when: foobar as when: not foobar are skipped. Only when: foobar should be skipped.

ansible-playbook -i inventory test.yml -e foobar=False

PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
"foobar": false
}

TASK [debug] *******************************************************************
skipping: [localhost]

TASK [debug] *******************************************************************
skipping: [localhost]

PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
"foobar": false
}

TASK [debug] *******************************************************************
skipping: [localhost]

TASK [debug] *******************************************************************
skipping: [localhost]

PLAY RECAP *********************************************************************

Note that the variable is interpreted as boolean as it displays 'foobar: false', while if I would pass -e foobar=false" it would show 'foobar: "false"' as it then gets interpreted as string. The only way I could get the example to work is when I change when: not foobar to when: not foobar|bool, but this isn't mentioned in the documentation at http://docs.ansible.com/ansible/playbooks_conditionals.html#the-when-statement (see use of boolean variable epic).

Any ideas how to resolve this issue?