diff options
| author | Brian Coca <brian.coca+git@gmail.com> | 2017-06-20 13:42:40 -0400 |
|---|---|---|
| committer | Brian Coca <bcoca@users.noreply.github.com> | 2017-06-20 14:27:53 -0400 |
| commit | 0bbf0e8d19d66ddaaa30822d709b18745e23a54c (patch) | |
| tree | 9ffbd57675cf667a483f96a682d4e67215014546 | |
| parent | 0296c2285be9c9c952f366439f5c95b78a3ea9bd (diff) | |
| download | ansible-0bbf0e8d19d66ddaaa30822d709b18745e23a54c.tar.gz | |
adjust script caching to processed data
also added filename to loading for better errors
| -rw-r--r-- | lib/ansible/plugins/inventory/script.py | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/lib/ansible/plugins/inventory/script.py b/lib/ansible/plugins/inventory/script.py index 44088057b1..3c8739ee49 100644 --- a/lib/ansible/plugins/inventory/script.py +++ b/lib/ansible/plugins/inventory/script.py @@ -84,9 +84,7 @@ class InventoryModule(BaseInventoryPlugin): try: cache_key = self.get_cache_prefix(path) - if cache and cache_key in inventory.cache: - data = inventory.cache[cache_key] - else: + if not cache or cache_key not in inventory.cache: try: sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) except OSError as e: @@ -107,14 +105,12 @@ class InventoryModule(BaseInventoryPlugin): except Exception as e: raise AnsibleError("Inventory {0} contained characters that cannot be interpreted as UTF-8: {1}".format(path, to_native(e))) - if cache: - inventory.cache[cache_key] = data - - try: - processed = self.loader.load(data) - except Exception as e: - raise AnsibleError("failed to parse executable inventory script results from {0}: {1}\n{2}".format(path, to_native(e), err)) + try: + inventory.cache[cache_key] = self.loader.load(data, file_name=path) + except Exception as e: + raise AnsibleError("failed to parse executable inventory script results from {0}: {1}\n{2}".format(path, to_native(e), err)) + processed = inventory.cache[cache_key] if not isinstance(processed, Mapping): raise AnsibleError("failed to parse executable inventory script results from {0}: needs to be a json dict\n{1}".format(path, err)) @@ -189,6 +185,6 @@ class InventoryModule(BaseInventoryPlugin): if out.strip() == '': return {} try: - return json_dict_bytes_to_unicode(self.loader.load(out)) + return json_dict_bytes_to_unicode(self.loader.load(out, file_name=path)) except ValueError: raise AnsibleError("could not parse post variable response: %s, %s" % (cmd, out)) |
