From 42a5cb5601187dda6e460099889ac9d74cd628b0 Mon Sep 17 00:00:00 2001 From: per-lind Date: Wed, 19 May 2021 15:00:24 +0200 Subject: [PATCH] Fix inventory plugin on Ansible 2.11 The bug here is that the openstack inventory plugin will no longer work with Ansible 2.11. You can test an inventory file (named openstack.yml) with either of these syntaxes: plugin: openstack plugin: openstack.cloud.openstack The first option errors due to custom validation present in openstack's own inventory plugin: [WARNING]: * Failed to parse /home/alancoding/repos/awx/testing/openstack/openstack.yml with auto plugin: plugin config file, but not for us: openstack Because this was written back before FQCNs (fully-qualified collection names) were a thing. Before it migrated to a collection, "openstack" was the expectation, but then self.NAME for the inventory plugin changed to "openstack.cloud.openstack", meaning that "openstack" by itself would no longer work. That made sense until Ansible core introduced routing where it would recognize "openstack" and route it to "openstack.cloud.openstack" for purposes of the "auto" inventory plugin routing. See the routing entry at: https://github.com/ansible/ansible/blob/2cbfd1e350cbe1ca195d33306b5a9628667ddda8/lib/ansible/config/ansible_builtin_runtime.yml#L9548 The second option errors with: [WARNING]: * Failed to parse /home/alancoding/repos/awx/testing/openstack_fqcn/openstack.yml with auto plugin: Invalid value "openstack.cloud.openstack" for configuration option "plugin_type: inventory plugin: ansible_collections.openstack.cloud.plugins.inventory.openstack setting: plugin ", valid values are: ['openstack'] This is due to Ansible core enforcing stricter validation of options. Merged in this PR ansible/ansible#73162 That broke many inventory plugins because the practice before the migration to collections was to list the name in the choices for the "plugin" option. This has been fixed in other collections. Because neither of these options work, the inventory plugin is not usable in recent Ansible versions. Suggested patch here: https://github.com/AlanCoding/ansible-collections-openstack/compare/fqcn_name?expand=1 This allows the user to use either syntax, because there's an argument for the validity of both. credit to https://github.com/AlanCoding Change-Id: Ie1211796929d0bc12c7a48764bd8efc7defdd2d7 --- plugins/inventory/openstack.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/inventory/openstack.py b/plugins/inventory/openstack.py index 32b5bcf7..b9ff5269 100644 --- a/plugins/inventory/openstack.py +++ b/plugins/inventory/openstack.py @@ -22,7 +22,7 @@ options: plugin: description: token that ensures this is a source file for the 'openstack' plugin. required: True - choices: ['openstack'] + choices: ['openstack', 'openstack.cloud.openstack'] show_all: description: toggles showing all vms vs only those with a working IP type: bool @@ -112,7 +112,7 @@ extends_documentation_fragment: EXAMPLES = ''' # file must be named openstack.yaml or openstack.yml # Make the plugin behave like the default behavior of the old script -plugin: openstack +plugin: openstack.cloud.openstack expand_hostvars: yes fail_on_errors: yes all_projects: yes @@ -159,7 +159,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): msg = '' if not self._config_data: msg = 'File empty. this is not my config file' - elif 'plugin' in self._config_data and self._config_data['plugin'] != self.NAME: + elif 'plugin' in self._config_data and self._config_data['plugin'] not in (self.NAME, 'openstack'): msg = 'plugin config file, but not for us: %s' % self._config_data['plugin'] elif 'plugin' not in self._config_data and 'clouds' not in self._config_data: msg = "it's not a plugin configuration nor a clouds.yaml file"