From 4561be00af27222ed80893183372a944428245b2 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 10 May 2016 17:16:05 -0400 Subject: [PATCH] simplified inventory error messaging --- lib/ansible/inventory/dir.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/ansible/inventory/dir.py b/lib/ansible/inventory/dir.py index 29a0c754b85..5a3d25fe5e3 100644 --- a/lib/ansible/inventory/dir.py +++ b/lib/ansible/inventory/dir.py @@ -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) )