From 174dfb432388d71f9273e256f6eab944565f93aa Mon Sep 17 00:00:00 2001 From: dridiha Date: Mon, 2 Mar 2026 21:52:24 +0100 Subject: [PATCH 1/3] [FIX-11365] Fix nmap cache misses when using pickle cache plugin --- changelogs/fragments/11365-pickle-cache-miss.yml | 2 ++ plugins/inventory/nmap.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/11365-pickle-cache-miss.yml diff --git a/changelogs/fragments/11365-pickle-cache-miss.yml b/changelogs/fragments/11365-pickle-cache-miss.yml new file mode 100644 index 0000000000..d4dd1ed902 --- /dev/null +++ b/changelogs/fragments/11365-pickle-cache-miss.yml @@ -0,0 +1,2 @@ +bugfixes: + - nmap with pickle as cache plugin - Fixed the cache misses due to the absence of the Plugin Interposer (Issue https://github.com/ansible-collections/community.general/issues/11365) \ No newline at end of file diff --git a/plugins/inventory/nmap.py b/plugins/inventory/nmap.py index c47d4228ab..7a7832fd3a 100644 --- a/plugins/inventory/nmap.py +++ b/plugins/inventory/nmap.py @@ -174,6 +174,16 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): valid = True return valid + + def _is_plugin_interposer(self): + return self._cache._plugin._persistent + + def _get_value_from_cache(self, cache_key): + if not self._is_plugin_interposer(): + self._cache[cache_key] = self._cache._plugin.get(cache_key) + self._cache._retrieved = self._cache + + return self._cache[cache_key] def parse(self, inventory, loader, path, cache=True): try: @@ -198,7 +208,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): if attempt_to_read_cache: try: - results = self._cache[cache_key] + results = self._get_value_from_cache(cache_key) except KeyError: # 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 From 0d56c96bcc8b23568b92e98f369a6c1228ee8a6c Mon Sep 17 00:00:00 2001 From: dridiha Date: Mon, 2 Mar 2026 22:29:51 +0100 Subject: [PATCH 2/3] Remove trailing white spaces --- plugins/inventory/nmap.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/inventory/nmap.py b/plugins/inventory/nmap.py index 7a7832fd3a..dc3fe579e9 100644 --- a/plugins/inventory/nmap.py +++ b/plugins/inventory/nmap.py @@ -174,15 +174,16 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): valid = True return valid - + def _is_plugin_interposer(self): return self._cache._plugin._persistent - + + def _get_value_from_cache(self, cache_key): if not self._is_plugin_interposer(): self._cache[cache_key] = self._cache._plugin.get(cache_key) - self._cache._retrieved = self._cache - + self._cache._retrieved = self._cache + return self._cache[cache_key] def parse(self, inventory, loader, path, cache=True): From 071c402ee177c359ed56fa715253a04c38372e74 Mon Sep 17 00:00:00 2001 From: dridiha Date: Mon, 2 Mar 2026 22:37:23 +0100 Subject: [PATCH 3/3] Remove extra empty line --- plugins/inventory/nmap.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/inventory/nmap.py b/plugins/inventory/nmap.py index dc3fe579e9..6f097bf691 100644 --- a/plugins/inventory/nmap.py +++ b/plugins/inventory/nmap.py @@ -178,7 +178,6 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): def _is_plugin_interposer(self): return self._cache._plugin._persistent - def _get_value_from_cache(self, cache_key): if not self._is_plugin_interposer(): self._cache[cache_key] = self._cache._plugin.get(cache_key)