Skip to content

Instantly share code, notes, and snippets.

@strootman
Created July 22, 2016 21:37
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 strootman/490cc62c865969e8744c220eb59e12ad to your computer and use it in GitHub Desktop.
Save strootman/490cc62c865969e8744c220eb59e12ad to your computer and use it in GitHub Desktop.
Example of using the `default()` jinja filter with a variable
# 1.
# $ ansible-playbook default-w-var-sub.yml
#
# PLAY [Test default variable using substitution] ********************************
#
# TASK [setup] *******************************************************************
# ok: [localhost]
#
# TASK [debug] *******************************************************************
# ok: [localhost] => {
# "override_variable": "I am a default"
# }
#
# PLAY RECAP *********************************************************************
# localhost : ok=2 changed=0 unreachable=0 failed=0
#
# 2.
# $ ansible-playbook default-w-var-sub.yml -e 'user_provided_var="what"'
#
# PLAY [Test default variable using substitution] ********************************
#
# TASK [setup] *******************************************************************
# ok: [localhost]
#
# TASK [debug] *******************************************************************
# ok: [localhost] => {
# "override_variable": "what"
# }
#
# PLAY RECAP *********************************************************************
# localhost : ok=2 changed=0 unreachable=0 failed=0
---
- name: Test default variable using substitution
hosts: localhost
vars:
default_variable: "I am a default"
override_variable: "{{ user_provided_var | default(default_variable) }}"
tasks:
- debug: var=override_variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment