mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
The following paths are now implict and optional in vars_files:
./group_vars/groupname.yml (for all groups the host is in) ./host_vars/hostname.yml (for the hostname given in the inventory) This requires an actual inventory file, not script and the paths are relative to the directory of the inventory file.
This commit is contained in:
parent
db1a4d8fac
commit
ba3466af95
3 changed files with 35 additions and 0 deletions
|
@ -203,6 +203,21 @@ class Play(object):
|
|||
if type(self.vars_files) != list:
|
||||
self.vars_files = [ self.vars_files ]
|
||||
|
||||
|
||||
if (host is not None):
|
||||
inventory = self.playbook.inventory
|
||||
hostrec = inventory.get_host(host)
|
||||
groups = [ g.name for g in hostrec.groups ]
|
||||
basedir = inventory.basedir()
|
||||
if basedir is not None:
|
||||
for x in groups:
|
||||
path = os.path.join(basedir, "group_vars/%s" % x)
|
||||
if os.path.exists(path):
|
||||
self.vars_files.append(path)
|
||||
path = os.path.join(basedir, "host_vars/%s" % hostrec.name)
|
||||
if os.path.exists(path):
|
||||
self.vars_files.append(path)
|
||||
|
||||
for filename in self.vars_files:
|
||||
|
||||
if type(filename) == list:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue