Indicate the intersection of groups as group_vars file inaccessible

I have specific variables that need to be applied based on group intersections in the inaccessible. For example, if the server is in prod mode and has a website function, I can specify it in the playbook using tag_function_website:&tag_mode_prod . This is great, but what should I do if I need to create a vars group file for this intersection with variables specific to the intersection (i.e. I do not want to use the same db for dev and prod, but I also have different dbs for boxes of different functions). I can’t use ampersand in the file name, so how do I create a file in the vars group to specify only those fields that fall into my desired intersection?

+6
source share
2 answers

Perhaps I really do not answer your question, rather sharing some of my experiences with Ansible.

First of all, you should consider the availability of separate stocks for different environments (you specify dev and prod). At first I started with one inventory, and I found this advice completely surprising: How to distinguish a stage from production .

The databases you used as an example are probably best referenced by individual variables (e.g. hrDb and acctDb).

+1
source

I had a similar goal, and I was able to come up with something that seemed to work. It depends on the observation of Marcin, but I will talk about some details. If you split the stocks between prod and stg, you can do the following ...

In your prod inventory, define the groups:

 [prod_website] #hosts go here... [website:children] prod_website 

Then, in your stg inventory, define similar groups:

 [stg_website] #hosts go here... [website:children] stg_website 

Then in the group_vars group you will create shafts for the intersection of the groups under prod_website and stg_website. When you call ansible and specify which inventory to use, it will pull the group intersection keys you need, but in your books you can still refer to a common group of websites, which is present in both prod and stg.

0
source

Source: https://habr.com/ru/post/980356/


All Articles