Created
June 2, 2018 02:53
-
-
Save dmsimard/02735c87909d9d7961d9e46dc0e7ec92 to your computer and use it in GitHub Desktop.
This behavior of Jinja always confuses in Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: localhost | |
gather_facts: no | |
vars: | |
thing: | |
tasks: | |
- name: Print double quotes | |
debug: | |
msg: "{{ thing | default('empty string') }}" | |
- name: Print empty string | |
debug: | |
msg: "{{ thing | default('empty string', True) }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ansible-playbook test.yml | |
PLAY [localhost] ******************************************************************* | |
TASK [Print double quotes] ********************************************************* | |
ok: [localhost] => { | |
"msg": "" | |
} | |
TASK [Print empty string] ********************************************************** | |
ok: [localhost] => { | |
"msg": "empty string" | |
} | |
PLAY RECAP ************************************************************************* | |
localhost : ok=2 changed=0 unreachable=0 failed=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> foo = "" | |
>>> if foo: | |
... print('oi') | |
... | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment