Skip to content

Instantly share code, notes, and snippets.

@hughsaunders
Created September 1, 2014 12:26
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 hughsaunders/517b7a1867cb5e87e7ad to your computer and use it in GitHub Desktop.
Save hughsaunders/517b7a1867cb5e87e7ad to your computer and use it in GitHub Desktop.
cb 1 (.venv) ~/git/test-playbook
$ ansible-playbook test.yml -i inventory/hosts
PLAY [test] *******************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [debug ] ****************************************************************
ok: [localhost] => (item=hostvars[groups['g1'][0]]['y']) => {
"hostvars[groups['g1'][0]]['y']": "{{x}}",
"item": "hostvars[groups['g1'][0]]['y']"
}
ok: [localhost] => (item=y) => {
"item": "y",
"y": "foo"
}
PLAY RECAP ********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
cb 1 (.venv) ~/git/test-playbook
$ cat inventory/hosts
[all]
localhost
[g1]
localhost
cb 1 (.venv) ~/git/test-playbook
$ cat inventory/group_vars/g1.yml
---
x: foo
y: "{{x}}"
cb 1 (.venv) ~/git/test-playbook
$ cat test.yml
---
- name: test
hosts: localhost
tasks:
- debug:
var: "{{item}}"
with_items:
- hostvars[groups['g1'][0]]['y']
- y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment