better inventory error messages

pull/17893/head
Brian Coca 8 years ago committed by Toshio Kuratomi
parent 0dea70bf37
commit 74b7590211

@ -25,6 +25,7 @@ import os
from ansible import constants as C from ansible import constants as C
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
from ansible.utils.vars import combine_vars from ansible.utils.vars import combine_vars
from ansible.module_utils._text import to_native
#FIXME: make into plugins #FIXME: make into plugins
from ansible.inventory.ini import InventoryParser as InventoryINIParser 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) parser = InventoryScript(loader=loader, groups=groups, filename=hostsfile)
processed = True processed = True
except Exception as e: 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: 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)) 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) parser = InventoryYAMLParser(loader=loader, groups=groups, filename=hostsfile)
processed = True processed = True
except Exception as e: except Exception as e:
myerr.append(str(e)) myerr.append('Attempted to read "%s" as YAML: %s' % (hostsfile, to_native(e)))
# ini # ini
if not processed and not shebang_present: 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) parser = InventoryINIParser(loader=loader, groups=groups, filename=hostsfile)
processed = True processed = True
except Exception as e: 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: if not processed and myerr:
raise AnsibleError('\n'.join(myerr)) raise AnsibleError('\n'.join(myerr))

Loading…
Cancel
Save