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:
Michael DeHaan 2012-07-20 09:43:45 -04:00
commit ba3466af95
3 changed files with 35 additions and 0 deletions

View file

@ -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: