Multi-dimensional group_vars ?

71 views
Skip to first unread message

Renaud Guerin

unread,
May 4, 2016, 8:04:53 AM5/4/16
to Ansible Project
Hi,

I have a variable "elasticsearch_heap_size" that can take 4 different values depending on 2 dimensions:
- the host being an Elasticsearch master or data node
- whether it's in production or development.

At the moment, I have 2 inventory files "production" and "development", and I set the variable directly within each using [elasticsearch-master:vars] and [elasticsearch-data:vars]

However, I know that setting variables inside static inventory files is discouraged in favor of using group_vars directories.

How would I go about doing this when the variable depends BOTH on production/development group membership ?

Thanks

Mike Biancaniello

unread,
May 4, 2016, 12:37:53 PM5/4/16
to Ansible Project
I like to set values like that in group_vars/all/<something_descriptive>.yml

e.g.
# file: group_vars/definitions.yml
---
elastic_search_values
:
  production
: 5
  development
: 3



# file: group_vars/elasticsearch-master.yml
elastic_search: production



# file: group_vars/elasticsearch-data.yml
elastic_search: development



Then reference it like:
{{ elastic_search_vars[elastic_search] }}




Reply all
Reply to author
Forward
0 new messages