I have a variable ourenv
that defines specific environment. This variable is defined in inventory file a used to load environment specific values via vars_files
as demonstrated in https://gist.github.com/marktheunissen/2979474
After upgrade to 1.8.0 I’m facing problem with loading environment specific properties via - []
syntax
Sample site.yml
---
- name: CheckIt
hosts: all
sudo: yes
gather_facts: yes
vars_files:
- ['vars/env_{{ourenv}}.yml', vars/env_defaults.yml]
tasks:
- name: debug
debug: msg="ourenv {{ ourenv }} pg_wal_buffers {{ pg_wal_buffers }}"
Sample inventory file
[singlebox]
localbox ourenv=dev_single host=devsrv ansible_ssh_host=192.168.18.129 alias=dev
Sample vars/env_dev_single.yml
pg_wal_buffers: 4MB
Sample vars/env_defaults.yml
pg_wal_buffers: value
Output in 1.8.X/1.9 (UNEXPECTED)
PLAY [CheckIt] ****************************************************************
GATHERING FACTS ***************************************************************
ok: [localbox]
TASK: [debug] *****************************************************************
ok: [localbox] => {
"msg": "ourenv dev_single pg_wal_buffers value"
}
Output in 1.4.X/…/1.7.2 (CORRECT)
PLAY [CheckIt] ****************************************************************
GATHERING FACTS ***************************************************************
ok: [localbox]
localbox: importing /bla-bla-bla/vars/env_dev_single.yml
TASK: [debug] *****************************************************************
ok: [localbox] => {
"msg": "ourenv dev_single pg_wal_buffers 4MB"
}
It seams to me that no issues with loading these variables directly if I replace - ['vars/env_{{ourenv}}.yml', vars/env_defaults.yml]
with - 'vars/env_{{ourenv}}.yml'
but I want to have ‘failback to defaults’ option.
Also if I pass ourenv
via command line (-e "ourenv=dev_single"
) it works as expected but I think it’s bad practice (splitting environment knowledge between inventory file and command line arguments).
Can somebody point me to the right direction?
I also opened ticket https://github.com/ansible/ansible/issues/10000 but hope to get faster response here.