better inventory error messages
This commit is contained in:
parent
0dea70bf37
commit
74b7590211
1 changed files with 4 additions and 3 deletions
|
@ -25,6 +25,7 @@ import os
|
|||
from ansible import constants as C
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.utils.vars import combine_vars
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
#FIXME: make into plugins
|
||||
from ansible.inventory.ini import InventoryParser as InventoryINIParser
|
||||
|
@ -59,7 +60,7 @@ def get_file_parser(hostsfile, groups, loader):
|
|||
parser = InventoryScript(loader=loader, groups=groups, filename=hostsfile)
|
||||
processed = True
|
||||
except Exception as e:
|
||||
myerr.append(str(e))
|
||||
myerr.append('Attempted to execute "%s" as inventory script: %s' % (hostsfile, to_native(e)))
|
||||
elif shebang_present:
|
||||
|
||||
myerr.append("The inventory 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))
|
||||
|
@ -70,7 +71,7 @@ def get_file_parser(hostsfile, groups, loader):
|
|||
parser = InventoryYAMLParser(loader=loader, groups=groups, filename=hostsfile)
|
||||
processed = True
|
||||
except Exception as e:
|
||||
myerr.append(str(e))
|
||||
myerr.append('Attempted to read "%s" as YAML: %s' % (hostsfile, to_native(e)))
|
||||
|
||||
# ini
|
||||
if not processed and not shebang_present:
|
||||
|
@ -78,7 +79,7 @@ def get_file_parser(hostsfile, groups, loader):
|
|||
parser = InventoryINIParser(loader=loader, groups=groups, filename=hostsfile)
|
||||
processed = True
|
||||
except Exception as e:
|
||||
myerr.append(str(e))
|
||||
myerr.append('Attempted to read "%s" as ini file: %s ' % (hostsfile, to_native(e)))
|
||||
|
||||
if not processed and myerr:
|
||||
raise AnsibleError('\n'.join(myerr))
|
||||
|
|
Loading…
Reference in a new issue