mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
simplified inventory error messaging
This commit is contained in:
@@ -52,6 +52,7 @@ def get_file_parser(hostsfile, groups, loader):
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
#FIXME: make this 'plugin loop'
|
||||
# script
|
||||
if loader.is_executable(hostsfile):
|
||||
@@ -59,9 +60,9 @@ def get_file_parser(hostsfile, groups, loader):
|
||||
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 + \
|
||||
"If this is not supposed to be an executable script, correct this with `chmod -x %s`." % hostsfile)
|
||||
myerr.append(str(e))
|
||||
elif shebang_present:
|
||||
myerr.append("The file %s looks like it should be an executable inventory script, but is not marked executable. Perhaps you want to correct this with `chmod +x %s`?" % (hostsfile, hostsfile))
|
||||
|
||||
# YAML/JSON
|
||||
if not processed and os.path.splitext(hostsfile)[-1] in C.YAML_FILENAME_EXTENSIONS:
|
||||
@@ -69,11 +70,7 @@ def get_file_parser(hostsfile, groups, loader):
|
||||
parser = InventoryYAMLParser(loader=loader, groups=groups, filename=hostsfile)
|
||||
processed = True
|
||||
except Exception as e:
|
||||
if shebang_present and not loader.is_executable(hostsfile):
|
||||
myerr.append("The file %s looks like it should be an executable inventory script, but is not marked executable. " % hostsfile + \
|
||||
"Perhaps you want to correct this with `chmod +x %s`?" % hostsfile)
|
||||
else:
|
||||
myerr.append(str(e))
|
||||
myerr.append(str(e))
|
||||
|
||||
# ini
|
||||
if not processed:
|
||||
@@ -81,11 +78,7 @@ def get_file_parser(hostsfile, groups, loader):
|
||||
parser = InventoryINIParser(loader=loader, groups=groups, filename=hostsfile)
|
||||
processed = True
|
||||
except Exception as e:
|
||||
if shebang_present and not loader.is_executable(hostsfile):
|
||||
myerr.append("The file %s looks like it should be an executable inventory script, but is not marked executable. " % hostsfile + \
|
||||
"Perhaps you want to correct this with `chmod +x %s`?" % hostsfile)
|
||||
else:
|
||||
myerr.append(str(e))
|
||||
myerr.append(str(e))
|
||||
|
||||
if not processed and myerr:
|
||||
raise AnsibleError( '\n'.join(myerr) )
|
||||
|
||||
Reference in New Issue
Block a user