I'm trying to set up environment specific variables in ansible (e.g. production, staging, development). For some reason, ansible is not picking up variables in group_vars/[environment].
I'm using ansible 1.9.1
Here's a stripped down example of what I'm trying to do.
Directory structure:
.
├── group_vars
│ └── staging
├── hosts
│ └── staging
└── site.yml
group_vars/staging:
test_var: "this is a test"
site.yml:
---
- hosts: localhost
tasks:
- debug: msg="test variable = {{ test_var }}"
hosts/staging is an empty file
Output of running ansible-playbook -i hosts/staging site.yml
:
PLAY [localhost] **************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [debug msg="test variable = {{ test_var }}"] ****************************
fatal: [localhost] => One or more undefined variables: 'test_var' is undefined
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/Users/jcowley/site.retry
localhost : ok=1 changed=0 unreachable=1 failed=0
If I move group_vars/staging to group_vars/all, it works as expected and outputs the value of test_var. But I'm trying to understand how I can separate environments per the documentation in Ansible's Best Practices