Skip to content

Instantly share code, notes, and snippets.

@cbrinker
Created June 27, 2013 17:21
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 cbrinker/5878410 to your computer and use it in GitHub Desktop.
Save cbrinker/5878410 to your computer and use it in GitHub Desktop.
$ cat group_vars/all
foo: bar
$ cat test.yml
---
# file: test.yml
- hosts: localhost
tasks:
- name: Create foo
template: src=foo.j2 dest=/tmp/foo
$ cat foo.j2
Hopefully this says bar = ${foo}
$ ansible-playbook -i /etc/ansible/hosts test.yml -CD
PLAY [localhost] **************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [Create foo] ************************************************************
--- before: /tmp/foo
+++ after: /Users/chris/work/configurator/ansible/foo.j2
@@ -1,0 +1,1 @@
+Hopefully this says bar = ${foo}
changed: [localhost]
PLAY RECAP ********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
=========================================================================================
===================== NOW adding a vars_files directive to playbook =====================
=========================================================================================
$ cat test.yml
---
# file: test.yml
- hosts: localhost
tasks:
- name: Create foo
template: src=foo.j2 dest=/tmp/foo
vars_files: # Not certain if this is required, but it doesn't seem to hurt¬
- "group_vars/all"
$ ansible-playbook -i /etc/ansible/hosts test.yml -CD
PLAY [localhost] **************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [Create foo] ************************************************************
--- before: /tmp/foo
+++ after: /Users/chris/work/configurator/ansible/foo.j2
@@ -1,0 +1,1 @@
+Hopefully this says bar = bar
changed: [localhost]
PLAY RECAP ********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
@cbrinker
Copy link
Author

For those seeing similar issues, There were 2 discoveries here.

1: the {{}} variable syntax > ${}
2: The group_vars/all file is searched for relative to the specified inventory location (/etc/ansible/group_vars/all by default apparently)

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