Allow the group_vars and host_vars directories to be stored alongside the playbook as well as inventory.

This commit is contained in:
Michael DeHaan 2013-06-01 10:38:16 -04:00
commit 6cd3ba5b06
3 changed files with 86 additions and 22 deletions

View file

@ -38,7 +38,7 @@ class Inventory(object):
__slots__ = [ 'host_list', 'groups', '_restriction', '_also_restriction', '_subset',
'parser', '_vars_per_host', '_vars_per_group', '_hosts_cache', '_groups_list',
'_vars_plugins']
'_vars_plugins', '_playbook_basedir']
def __init__(self, host_list=C.DEFAULT_HOST_LIST):
@ -54,6 +54,9 @@ class Inventory(object):
self._hosts_cache = {}
self._groups_list = {}
# to be set by calling set_playbook_basedir by ansible-playbook
self._playbook_basedir = None
# the inventory object holds a list of groups
self.groups = []
@ -372,3 +375,16 @@ class Inventory(object):
if not self.is_file():
return None
return os.path.dirname(self.host_list)
def playbook_basedir(self):
""" returns the directory of the current playbook """
return self._playbook_basedir
def set_playbook_basedir(self, dir):
"""
sets the base directory of the playbook so inventory plugins can use it to find
variable files and other things.
"""
self._playbook_basedir = dir