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 d9109177a90..bb050314674 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 73817a46506..b9a02f7b694 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): if path in self._file_mapping: return self.load(self._file_mapping[path], path) return None