From af85b6c20320af1284b942a3bc6fca2a0495c75a Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 17 May 2021 08:09:58 +0200 Subject: [PATCH] fix error when cache is disabled (#2518) (#2532) (cherry picked from commit 448b8cbcda019e1d89eb715dfb6fc2f754440613) Co-authored-by: Dennis Israelsson --- changelogs/fragments/2518-nmap-fix-cache-disabled.yml | 2 ++ plugins/inventory/nmap.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/2518-nmap-fix-cache-disabled.yml diff --git a/changelogs/fragments/2518-nmap-fix-cache-disabled.yml b/changelogs/fragments/2518-nmap-fix-cache-disabled.yml new file mode 100644 index 0000000000..8f4680b6a6 --- /dev/null +++ b/changelogs/fragments/2518-nmap-fix-cache-disabled.yml @@ -0,0 +1,2 @@ +bugfixes: + - nmap inventory plugin - fix local variable error when cache is disabled (https://github.com/ansible-collections/community.general/issues/2512). diff --git a/plugins/inventory/nmap.py b/plugins/inventory/nmap.py index 687317abfa..39a6ff3a67 100644 --- a/plugins/inventory/nmap.py +++ b/plugins/inventory/nmap.py @@ -130,7 +130,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): # This occurs if the cache_key is not in the cache or if the cache_key expired, so the cache needs to be updated cache_needs_update = True - if cache_needs_update: + if not user_cache_setting or cache_needs_update: # setup command cmd = [self._nmap] if not self._options['ports']: @@ -207,6 +207,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): except Exception as e: raise AnsibleParserError("failed to parse %s: %s " % (to_native(path), to_native(e))) + if cache_needs_update: self._cache[cache_key] = results self._populate(results)