From what I understood reading about the topic, null
and "{{ None }}"
are basically the same thing in Ansible. The difference is that the former is language agnostic YAML syntax and the latter is Python specific (I do not speak that language so I do not know how correct that is). However, as the following Ansible playbook shows, they are different.
- hosts: localhost
vars:
a: null
b: "{{ None }}"
tasks:
- name: a always
debug:
var: a
- name: a if none
debug:
var: a
when: a==None
- name: a if not none
debug:
var: a
when: a!=None
- name: b always
debug:
var: b
- name: b if none
debug:
var: b
when: b==None
- name: b if not none
debug:
var: b
when: b!=None
The output from the above is this:
PLAY [localhost] *******************************************************************************************************************************************************************************
TASK [Gathering Facts] *************************************************************************************************************************************************************************
ok: [localhost]
TASK [a always] ********************************************************************************************************************************************************************************
ok: [localhost] => {
"a": null
}
TASK [a if none] *******************************************************************************************************************************************************************************
ok: [localhost] => {
"a": null
}
TASK [a if not none] ***************************************************************************************************************************************************************************
skipping: [localhost]
TASK [b always] ********************************************************************************************************************************************************************************
ok: [localhost] => {
"b": ""
}
TASK [b if none] *******************************************************************************************************************************************************************************
skipping: [localhost]
TASK [b if not none] ***************************************************************************************************************************************************************************
ok: [localhost] => {
"b": ""
}
PLAY RECAP *************************************************************************************************************************************************************************************
localhost : ok=5 changed=0 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0
I am not so much concerned about the output null
vs. ""
, but what really bothers me is the different test results a==None
compared to b==None
.
Can somebody please help me understand what I am missing here?