Skip to content

Instantly share code, notes, and snippets.

@rektide
Created September 25, 2014 03:41
Show Gist options
  • Save rektide/164b80c9b120361759b2 to your computer and use it in GitHub Desktop.
Save rektide/164b80c9b120361759b2 to your computer and use it in GitHub Desktop.
ansible with uninitialized vars
---
- hosts: all
gather_facts: False
vars:
foo: "one"
bar: "{{tbd}}"
tasks:
# this first line will fail, saying: fatal: [127.0.0.1] => One or more undefined variables: 'tbd' is undefined
- debug: msg="{{vars['foo']|default('nope')}}"
# but these would have been fine
- set_fact: tbd="two"
- debug: msg="{{vars['foo']|default('nope')}}"
- debug: msg="{{vars['doesnotexist']|default('nope')}}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment