Skip to content

Instantly share code, notes, and snippets.

@dmsimard
Created June 2, 2018 02:53
Show Gist options
  • Save dmsimard/02735c87909d9d7961d9e46dc0e7ec92 to your computer and use it in GitHub Desktop.
Save dmsimard/02735c87909d9d7961d9e46dc0e7ec92 to your computer and use it in GitHub Desktop.
This behavior of Jinja always confuses in Ansible
- 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) }}"
# 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
>>> foo = ""
>>> if foo:
... print('oi')
...
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment