ansible/ansible — pull request #5465 by deonbredenhann (2013-12-31 13:38:46+00:00)
Title: Treat a False mandatory variable as defined.

When a variable is set to False, the "mandatory" filter returns False even if the variable is set. This is not expected behaviour. This patch will check if the variable exists and return True even if the value of the variable is False.

host_vars/vbox1.example.com
```yaml
var_test: no
```

host_vars/vbox2.example.com
```yaml
var_test: yes
```

tasks.yml
```yaml
- debug: var=var_test

- name: Test var
file:
state: touch
path: /root/var
when: "{{ var_test | mandatory }}"
```

Output.
```
TASK: [test | debug var=var_test] *********************************************
ok: [vbox1.example.com] => {
"item": "",
"var_test": "False"
}
ok: [vbox2.example.com] => {
"item": "",
"var_test": "True"
}

TASK: [test | Test var] *******************************************************
fatal: [vbox1.example.com] => Mandatory variable not defined.
changed: [vbox2.example.com] => {"changed": true, "dest": "/root/var", "gid": 0, "group": "root", "item": "", "mode": "0644", "owner": "root", "size": 0, "state": "file", "uid": 0}
```