developing_inventory sample code: fix undefined var "results" if get_option(cache)=False (#72977)

if user_cache_setting == False, then the previous code didn't parse the inventory source
This commit is contained in:
azrdev 2020-12-16 16:51:58 +01:00 committed by GitHub
parent 3274e02fd8
commit 6487a239c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -254,13 +254,13 @@ Now that you've enabled caching, loaded the correct plugin, and retrieved a uniq
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
if cache_needs_update:
if not attempt_to_read_cache or cache_needs_update:
# parse the provided inventory source
results = self.get_inventory()
# set the cache
if cache_needs_update:
self._cache[cache_key] = results
# submit the parsed data to the inventory object (add_host, set_variable, etc)
self.populate(results)
After the ``parse`` method is complete, the contents of ``self._cache`` is used to set the cache plugin if the contents of the cache have changed.