Skip to content

Instantly share code, notes, and snippets.

@berlic
Created March 8, 2017 07:25
Show Gist options
  • Save berlic/26a427ea613a8b2edbbb114ece93d2b1 to your computer and use it in GitHub Desktop.
Save berlic/26a427ea613a8b2edbbb114ece93d2b1 to your computer and use it in GitHub Desktop.
Show problems when accessing vars via undocumented `vars` dict
---
- hosts: localhost
gather_facts: no
vars:
var1: hello
var2: "{{ var1 }}"
var_name: var2
tasks:
- debug: msg="{{ var2 }}"
- debug: msg="{{ vars[var_name] }}"
@MeneDev
Copy link

MeneDev commented Mar 8, 2017

For reference, this is the output:

Command: ansible-playbook -c local vars_demo.yml

PLAY [localhost] ***************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => {
    "msg": "hello"
}

TASK [debug] *******************************************************************
ok: [localhost] => {
    "msg": "{{ var1 }}"
}

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0   

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment