Skip to content

Instantly share code, notes, and snippets.

@halberom
Created June 12, 2019 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halberom/237d38958e64d7513e83df0962d1fb4e to your computer and use it in GitHub Desktop.
Save halberom/237d38958e64d7513e83df0962d1fb4e to your computer and use it in GitHub Desktop.
ansible - example of using default() with different var states
---
- hosts: localhost
gather_facts: false
vars:
foo: ''
bar: foo
#abc
xyz: true
tasks:
- debug:
msg: "{{ foo|default(false) }}"
- debug:
msg: "{{ foo|default(false, true) }}"
- debug:
msg: "{{ bar|default(false) }}"
- debug:
msg: "{{ bar|default(false, true) }}"
- debug:
msg: "{{ abc|default(false) }}"
- debug:
msg: "{{ abc|default(false, true) }}"
- debug:
msg: "{{ xyz|default(false) }}"
- debug:
msg: "{{ xyz|default(false, true) }}"
PLAY [localhost] *********************************************************************************************************************************************************************
TASK [debug] *************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": ""
}
TASK [debug] *************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": false
}
TASK [debug] *************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "foo"
}
TASK [debug] *************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "foo"
}
TASK [debug] *************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": false
}
TASK [debug] *************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": false
}
TASK [debug] *************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": true
}
TASK [debug] *************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment