Update inventory caching to remove deprecation warnings (#53976)

This commit is contained in:
Sloane Hertel 2019-03-26 08:15:12 -05:00 committed by GitHub
parent 1a5732807f
commit a93154c57f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 14 deletions

View file

@ -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)