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..6f097bf691 100644 --- a/plugins/inventory/nmap.py +++ b/plugins/inventory/nmap.py @@ -175,6 +175,16 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): 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: self._nmap = get_bin_path("nmap") @@ -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