From 851725d72a108dcc5eb164cab4fa2f6119f7d56e Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Tue, 3 Jul 2018 18:07:35 -0400 Subject: [PATCH] Fix setting required options for inventory plugins - backport/2.6/42049 (#42120) * Fix setting required options for inventory plugins (#42049) * Fix setting required options for inventory plugins * call set_options for yaml and script plugin (cherry picked from commit 44e58863855b939de2e5911f94e291d36bad7516) * changelog --- .../inventory_manager_fix_required_options_override.yaml | 5 +++++ lib/ansible/inventory/manager.py | 1 - lib/ansible/plugins/inventory/script.py | 1 + lib/ansible/plugins/inventory/yaml.py | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/inventory_manager_fix_required_options_override.yaml diff --git a/changelogs/fragments/inventory_manager_fix_required_options_override.yaml b/changelogs/fragments/inventory_manager_fix_required_options_override.yaml new file mode 100644 index 00000000000..30c4565ff7e --- /dev/null +++ b/changelogs/fragments/inventory_manager_fix_required_options_override.yaml @@ -0,0 +1,5 @@ +--- +bugfixes: +- inventory manager - This fixes required options being populated before the + inventory config file is read, so the required options may be set in the + config file. diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py index b307d460827..2efc67aa942 100644 --- a/lib/ansible/inventory/manager.py +++ b/lib/ansible/inventory/manager.py @@ -183,7 +183,6 @@ class InventoryManager(object): for name in C.INVENTORY_ENABLED: plugin = inventory_loader.get(name) if plugin: - plugin.set_options() self._inventory_plugins.append(plugin) else: display.warning('Failed to load inventory plugin, skipping %s' % name) diff --git a/lib/ansible/plugins/inventory/script.py b/lib/ansible/plugins/inventory/script.py index 0876649331e..8bc1de73116 100644 --- a/lib/ansible/plugins/inventory/script.py +++ b/lib/ansible/plugins/inventory/script.py @@ -85,6 +85,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable): def parse(self, inventory, loader, path, cache=None): super(InventoryModule, self).parse(inventory, loader, path) + self.set_options() if cache is None: cache = self.get_option('cache') diff --git a/lib/ansible/plugins/inventory/yaml.py b/lib/ansible/plugins/inventory/yaml.py index 5983ce06749..436dbb6bdb4 100644 --- a/lib/ansible/plugins/inventory/yaml.py +++ b/lib/ansible/plugins/inventory/yaml.py @@ -90,6 +90,7 @@ class InventoryModule(BaseFileInventoryPlugin): ''' parses the inventory file ''' super(InventoryModule, self).parse(inventory, loader, path) + self.set_options() try: data = self.loader.load_from_file(path, cache=False)