Created
July 22, 2016 21:37
-
-
Save strootman/490cc62c865969e8744c220eb59e12ad to your computer and use it in GitHub Desktop.
Example of using the `default()` jinja filter with a variable
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
# 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