Closed pijpe00 closed 5 years ago
There is no such thing as an "active group". When you use something like hosts: some_group
(or even hosts: some_group:another_group
or hosts: some_host
) in your play, that is flattened into a list of hosts and the original host pattern (which may not have even contained a group) is "lost".
There's already a variable called group_names
, which contains a list of all inventory groups that the current host is a member of, regardless of how that host was selected. You can use that variable similarly to your proposed ansible_play_group
variable.
As a side note, it's "wrong" to use include_vars
on a file in defaults/
, even though it technically works. The vars file will be treated like any other vars file, rather than having the normal precedence used for role defaults.
Hello @agaffney ,
I want to use seperate yaml files to organise my variables.
Is there a way I can include variables from the group_vars/
What I want to do is: the variable 'app' consistes of the information "
As explained above, there is no such thing as 'active group', consider the following hosts expression:
hosts: vmhosts:dc1:!webservers
In which plenty of servers are both in vmhosts and dc1 groups, which one would you consider "active"?
This proposal is based on several incorrect assumptions:
hosts:
clause (we use them to generate a 'list of hosts' and that is what we keep track of)As such this is not a possible proposal w/o changing the fundamental way Ansible works (centered on Host and Task).
@pijpe00
The group_vars are ALWAYS read for ALL the groups your host is part of, doing an include of specific group_vars is redundant and shows incorrect assumptions in your variable organization.
Do not use the same variable across groups that needs different values depending on group targeted, Ansible does not work that way (we know other tools do, its a valid approach, but not the one we take).
Hi Andrew (@agaffney) , Brian (@bcoca), The problem I have is: I made yaml playbooks I want to use for
development, test, production I get information from several teams for the each desig phase. for example: development --> team1 --> several variables like database locations, datasources etc development --> team2 --> several variables like database locations, datasources etc test --> team1 --> several variables like database locations, datasources etc test --> team2 --> several variables like database locations, datasources etc production --> team1 --> several variables like database locations, datasources etc production --> team2 --> several variables like database locations, datasources etc
varn: zzz
varn: azz
Depends on what stage I am the variables has other values What is the right direction to implement this without?
This is not a forum for user support. You can come over to the #ansible
channel on Freenode or post to the ansible-project
mailing list.
Proposal: active group of the play
Author: Edwin
Date: 2018-04-09
Motivation
I want to know which group the playbook is running (ansible_play_group).
Problems
What problems exist that this proposal will solve?
Solution proposal
directory structure: . roles roles/webserver roles/webserver/defaults roles/webserver/defaults/France roles/webserver/defaults/France/info1.yml roles/webserver/defaults/France/info2.yml roles/webserver/defaults/Greece roles/webserver/defaults/Greece/info1.yml roles/webserver/defaults/Greece/info2.yml