Cleaning up default group creation in inventory parsers

This commit is contained in:
James Cammarata 2015-09-16 11:27:03 -04:00
parent e899b8e70d
commit c8f2483d6d
4 changed files with 42 additions and 53 deletions

View file

@ -34,7 +34,7 @@ from ansible.inventory.script import InventoryScript
__all__ = ['get_file_parser']
def get_file_parser(hostsfile, loader):
def get_file_parser(hostsfile, groups, loader):
# check to see if the specified file starts with a
# shebang (#!/), so if an error is raised by the parser
# class we can show a more apropos error
@ -55,7 +55,7 @@ def get_file_parser(hostsfile, loader):
if loader.is_executable(hostsfile):
try:
parser = InventoryScript(loader=loader, filename=hostsfile)
parser = InventoryScript(loader=loader, groups=groups, filename=hostsfile)
processed = True
except Exception as e:
myerr.append("The file %s is marked as executable, but failed to execute correctly. " % hostsfile + \
@ -64,7 +64,7 @@ def get_file_parser(hostsfile, loader):
if not processed:
try:
parser = InventoryINIParser(loader=loader, filename=hostsfile)
parser = InventoryINIParser(loader=loader, groups=groups, filename=hostsfile)
processed = True
except Exception as e:
if shebang_present and not loader.is_executable(hostsfile):
@ -81,13 +81,13 @@ def get_file_parser(hostsfile, loader):
class InventoryDirectory(object):
''' Host inventory parser for ansible using a directory of inventories. '''
def __init__(self, loader, filename=C.DEFAULT_HOST_LIST):
def __init__(self, loader, groups=dict(), filename=C.DEFAULT_HOST_LIST):
self.names = os.listdir(filename)
self.names.sort()
self.directory = filename
self.parsers = []
self.hosts = {}
self.groups = {}
self.groups = groups
self._loader = loader