mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-30 06:11:26 -07:00
Update inventory caching to remove deprecation warnings (#53976)
This commit is contained in:
parent
1a5732807f
commit
a93154c57f
6 changed files with 19 additions and 14 deletions
|
@ -156,14 +156,19 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
if 'clouds' in self._config_data:
|
||||
self._config_data = {}
|
||||
|
||||
# update cache if the user has caching enabled and the cache is being refreshed
|
||||
# will update variable below in the case of an expired cache
|
||||
cache_needs_update = not cache and self.get_option('cache')
|
||||
|
||||
if cache:
|
||||
cache = self.get_option('cache')
|
||||
source_data = None
|
||||
if cache:
|
||||
try:
|
||||
source_data = self.cache.get(cache_key)
|
||||
source_data = self._cache[cache_key]
|
||||
except KeyError:
|
||||
pass
|
||||
# cache expired or doesn't exist yet
|
||||
cache_needs_update = True
|
||||
|
||||
if not source_data:
|
||||
clouds_yaml_path = self._config_data.get('clouds_yaml_path')
|
||||
|
@ -199,8 +204,8 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
source_data = cloud_inventory.list_hosts(
|
||||
expand=expand_hostvars, fail_on_cloud_config=fail_on_errors)
|
||||
|
||||
if self.cache is not None:
|
||||
self.cache.set(cache_key, source_data)
|
||||
if cache_needs_update:
|
||||
self._cache[cache_key] = source_data
|
||||
|
||||
self._populate_from_source(source_data)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue