1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Make inventory basedir for directory based inventory be the directory

This puts host_vars and group_vars inside of the directory, allowing you
to target a single inventory but still have access to the variables.
This commit is contained in:
Daniel Hokka Zakrisson 2013-02-28 16:58:09 +01:00
parent d9c6b60b24
commit ad08995989
2 changed files with 7 additions and 3 deletions

View file

@ -66,9 +66,6 @@ class Inventory(object):
host_list = host_list.split(",") host_list = host_list.split(",")
host_list = [ h for h in host_list if h and h.strip() ] host_list = [ h for h in host_list if h and h.strip() ]
else:
utils.plugins.vars_loader.add_directory(self.basedir())
if type(host_list) == list: if type(host_list) == list:
all = Group('all') all = Group('all')
self.groups = [ all ] self.groups = [ all ]
@ -80,6 +77,8 @@ class Inventory(object):
all.add_host(Host(x)) all.add_host(Host(x))
elif os.path.exists(host_list): elif os.path.exists(host_list):
if os.path.isdir(host_list): if os.path.isdir(host_list):
# Ensure basedir is inside the directory
self.host_list = os.path.join(self.host_list, "")
self.parser = InventoryDirectory(filename=host_list) self.parser = InventoryDirectory(filename=host_list)
self.groups = self.parser.groups.values() self.groups = self.parser.groups.values()
elif utils.is_executable(host_list): elif utils.is_executable(host_list):
@ -92,6 +91,8 @@ class Inventory(object):
self.groups = self.parser.groups.values() self.groups = self.parser.groups.values()
else: else:
raise errors.AnsibleError("YAML inventory support is deprecated in 0.6 and removed in 0.7, see the migration script in examples/scripts in the git checkout") raise errors.AnsibleError("YAML inventory support is deprecated in 0.6 and removed in 0.7, see the migration script in examples/scripts in the git checkout")
utils.plugins.vars_loader.add_directory(self.basedir())
else: else:
raise errors.AnsibleError("Unable to find an inventory file, specify one with -i ?") raise errors.AnsibleError("Unable to find an inventory file, specify one with -i ?")

View file

@ -39,6 +39,9 @@ class InventoryDirectory(object):
for i in self.names: for i in self.names:
if i.endswith("~") or i.endswith(".orig") or i.endswith(".bak"): if i.endswith("~") or i.endswith(".orig") or i.endswith(".bak"):
continue continue
# These are things inside of an inventory basedir
if i in ("host_vars", "group_vars", "vars_plugins"):
continue
fullpath = os.path.join(self.directory, i) fullpath = os.path.join(self.directory, i)
if os.path.isdir(fullpath): if os.path.isdir(fullpath):
parser = InventoryDirectory(filename=fullpath) parser = InventoryDirectory(filename=fullpath)