From 97a3e59ce8c0df534586d313411b45d3e717e6fb Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 12 Oct 2018 11:27:29 -0400 Subject: [PATCH] better information for user from inventory plugins (#46766) * better information for user from inventory plugins - use foreman as example (cherry picked from commit 9e0c2a658f48246f644d7f477ec5184ac0ffa580) --- changelogs/fragments/inv_fixes.yml | 2 ++ lib/ansible/inventory/manager.py | 2 +- lib/ansible/plugins/inventory/__init__.py | 7 ++++++- lib/ansible/plugins/inventory/foreman.py | 6 ++++-- 4 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/inv_fixes.yml diff --git a/changelogs/fragments/inv_fixes.yml b/changelogs/fragments/inv_fixes.yml new file mode 100644 index 00000000000..8d3c52d77ce --- /dev/null +++ b/changelogs/fragments/inv_fixes.yml @@ -0,0 +1,2 @@ +bugfixes: + - Give user better error messages and more information on verbose about inventory plugin behaviour diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py index 12727fabcda..fc39e25db2b 100644 --- a/lib/ansible/inventory/manager.py +++ b/lib/ansible/inventory/manager.py @@ -278,7 +278,7 @@ class InventoryManager(object): display.debug('%s failed to parse %s' % (plugin_name, source)) failures.append({'src': source, 'plugin': plugin_name, 'exc': AnsibleError(e)}) else: - display.debug('%s did not meet %s requirements' % (source, plugin_name)) + display.v('%s did not meet %s requirements, check plugin documentation if this is unexpected' % (source, plugin_name)) else: if not parsed and failures: # only if no plugin processed files should we show errors. diff --git a/lib/ansible/plugins/inventory/__init__.py b/lib/ansible/plugins/inventory/__init__.py index 77159eaaecd..9f0919dd5a1 100644 --- a/lib/ansible/plugins/inventory/__init__.py +++ b/lib/ansible/plugins/inventory/__init__.py @@ -171,8 +171,13 @@ class BaseInventoryPlugin(AnsiblePlugin): So only call this base class if you expect it to be a file. ''' + valid = False b_path = to_bytes(path, errors='surrogate_or_strict') - return (os.path.exists(b_path) and os.access(b_path, os.R_OK)) + if (os.path.exists(b_path) and os.access(b_path, os.R_OK)): + valid = True + else: + self.display.vvv('Skipping due to inventory source not existing or not being readable by the current user') + return valid def _populate_host_vars(self, hosts, variables, group=None, port=None): if not isinstance(variables, Mapping): diff --git a/lib/ansible/plugins/inventory/foreman.py b/lib/ansible/plugins/inventory/foreman.py index 7b2829c08d8..47a71d8ba84 100644 --- a/lib/ansible/plugins/inventory/foreman.py +++ b/lib/ansible/plugins/inventory/foreman.py @@ -14,7 +14,7 @@ DOCUMENTATION = ''' - requests >= 1.1 description: - Get inventory hosts from the foreman service. - - "Uses a configuration file as an inventory source, it must end in foreman.yml or foreman.yaml and has a ``plugin: foreman`` entry." + - "Uses a configuration file as an inventory source, it must end in ``.foreman.yml`` or ``.foreman.yaml`` and has a ``plugin: foreman`` entry." extends_documentation_fragment: - inventory_cache options: @@ -29,7 +29,7 @@ DOCUMENTATION = ''' description: foreman authentication user required: True password: - description: forman authentication password + description: foreman authentication password required: True validate_certs: description: verify SSL certificate if using https @@ -102,6 +102,8 @@ class InventoryModule(BaseInventoryPlugin, Cacheable): if super(InventoryModule, self).verify_file(path): if path.endswith('.foreman.yaml') or path.endswith('.foreman.yml'): valid = True + else: + self.display.vvv('Skipping due to inventory source not ending in "foreman.yaml" nor "foreman.yml"') return valid def _get_session(self):