From 80486090d5179bff11d6b47506219431c17b331e Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 22 Feb 2018 11:53:40 -0500 Subject: [PATCH] protect against plugins using verify incorrectly assume false on any errors (cherry picked from commit ef40e5e3b21fe05df3ed5691360ea51ce84a66c2) backport of #36591 --- changelogs/fragments/protect_bad_verify.yml | 2 ++ lib/ansible/inventory/manager.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/protect_bad_verify.yml diff --git a/changelogs/fragments/protect_bad_verify.yml b/changelogs/fragments/protect_bad_verify.yml new file mode 100644 index 0000000000..82eb1e121b --- /dev/null +++ b/changelogs/fragments/protect_bad_verify.yml @@ -0,0 +1,2 @@ +bugfixes: + - protect against bad plugin verify method https://github.com/ansible/ansible/pull/36591 diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py index 719a333e9b..db21af6f05 100644 --- a/lib/ansible/inventory/manager.py +++ b/lib/ansible/inventory/manager.py @@ -257,8 +257,13 @@ class InventoryManager(object): plugin_name = to_native(getattr(plugin, '_load_name', getattr(plugin, '_original_path', ''))) display.debug(u'Attempting to use plugin %s (%s)' % (plugin_name, plugin._original_path)) - # initialize - if plugin.verify_file(source): + # initialize and figure out if plugin wants to attempt parsing this file + try: + plugin_wants = bool(plugin.verify_file(source)) + except Exception: + plugin_wants = False + + if plugin_wants: try: # in case plugin fails 1/2 way we dont want partial inventory plugin.parse(self._inventory, self._loader, source, cache=cache)