From 74b75902118c43162a5d4a9e679df0fea8251a18 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 4 Oct 2016 10:20:54 -0400 Subject: [PATCH] better inventory error messages --- lib/ansible/inventory/dir.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ansible/inventory/dir.py b/lib/ansible/inventory/dir.py index b1f9ec4f1ea..7287f7804d1 100644 --- a/lib/ansible/inventory/dir.py +++ b/lib/ansible/inventory/dir.py @@ -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))