mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 03:00:23 -07:00
Introduce group_names in template variables.
This is a list of all the groups a host is in.
This commit is contained in:
parent
6341361a5b
commit
b87710a1df
3 changed files with 33 additions and 11 deletions
|
@ -81,13 +81,19 @@ class Inventory(object):
|
|||
def get_variables(self, host):
|
||||
""" Return the variables associated with this host. """
|
||||
|
||||
variables = {}
|
||||
if host in self._variables:
|
||||
return self._variables[host].copy()
|
||||
variables.update(self._variables[host].copy())
|
||||
|
||||
if not self._is_script:
|
||||
return {}
|
||||
if self._is_script:
|
||||
variables.update(self._get_variables_from_script(host))
|
||||
|
||||
return self._get_variables_from_script(host)
|
||||
variables['group_names'] = []
|
||||
for name,hosts in self.groups.iteritems():
|
||||
if host in hosts:
|
||||
variables['group_names'].append(name)
|
||||
|
||||
return variables
|
||||
|
||||
# *****************************************************
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue