From 886c4edfb9097b76af42d2aa570d66f60037df4a Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 10 Apr 2018 22:15:52 -0400 Subject: [PATCH] avoid caching invetnory sources in loader (#38242) * fix inventory plugin source caching - avoid caching invetnory sources in loader in base - same fix for yaml plugin - idem for 'auto' plugin fixes #37162 * fix mock dataloader func sig --- lib/ansible/plugins/inventory/__init__.py | 4 +++- lib/ansible/plugins/inventory/auto.py | 2 +- lib/ansible/plugins/inventory/ini.py | 3 +-- lib/ansible/plugins/inventory/yaml.py | 2 +- test/units/mock/loader.py | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/ansible/plugins/inventory/__init__.py b/lib/ansible/plugins/inventory/__init__.py index 5f5fc9eb159..1488b99ae0b 100644 --- a/lib/ansible/plugins/inventory/__init__.py +++ b/lib/ansible/plugins/inventory/__init__.py @@ -172,7 +172,9 @@ class BaseInventoryPlugin(AnsiblePlugin): config = {} try: - config = self.loader.load_from_file(path) + # avoid loader cache so meta: refresh_inventory can pick up config changes + # if we read more than once, fs cache should be good enough + config = self.loader.load_from_file(path, cache=False) except Exception as e: raise AnsibleParserError(to_native(e)) diff --git a/lib/ansible/plugins/inventory/auto.py b/lib/ansible/plugins/inventory/auto.py index c2bd7f8ef57..62502c36cef 100644 --- a/lib/ansible/plugins/inventory/auto.py +++ b/lib/ansible/plugins/inventory/auto.py @@ -38,7 +38,7 @@ class InventoryModule(BaseInventoryPlugin): return super(InventoryModule, self).verify_file(path) def parse(self, inventory, loader, path, cache=True): - config_data = loader.load_from_file(path) + config_data = loader.load_from_file(path, cache=False) plugin_name = config_data.get('plugin') diff --git a/lib/ansible/plugins/inventory/ini.py b/lib/ansible/plugins/inventory/ini.py index 82d4e1899d6..93afcf1898f 100644 --- a/lib/ansible/plugins/inventory/ini.py +++ b/lib/ansible/plugins/inventory/ini.py @@ -104,8 +104,7 @@ class InventoryModule(BaseFileInventoryPlugin): self._filename = path try: - # Read in the hosts, groups, and variables defined in the - # inventory file. + # Read in the hosts, groups, and variables defined in the inventory file. if self.loader: (b_data, private) = self.loader._get_file_contents(path) else: diff --git a/lib/ansible/plugins/inventory/yaml.py b/lib/ansible/plugins/inventory/yaml.py index 1ff0cff9a6e..1e545f9bbd5 100644 --- a/lib/ansible/plugins/inventory/yaml.py +++ b/lib/ansible/plugins/inventory/yaml.py @@ -91,7 +91,7 @@ class InventoryModule(BaseFileInventoryPlugin): super(InventoryModule, self).parse(inventory, loader, path) try: - data = self.loader.load_from_file(path) + data = self.loader.load_from_file(path, cache=False) except Exception as e: raise AnsibleParserError(e) diff --git a/test/units/mock/loader.py b/test/units/mock/loader.py index 793a891536d..0ee47fbb9f5 100644 --- a/test/units/mock/loader.py +++ b/test/units/mock/loader.py @@ -38,7 +38,7 @@ class DictDataLoader(DataLoader): self._build_known_directories() self._vault_secrets = None - def load_from_file(self, path, unsafe=False): + def load_from_file(self, path, cache=True, unsafe=False): path = to_text(path) if path in self._file_mapping: return self.load(self._file_mapping[path], path)