From 6d3db56c2acf56de0c33746be64d6b1d6a032cfc Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Tue, 4 Sep 2018 17:39:01 -0500 Subject: [PATCH] Fix openstack inventory plugin (#43581) * Fix openstack inventory script for multi-cloud case The shift to openstacksdk left us with a bug in that when running bare with --list, the cloud argument to get_one is None. We just need _one_ of the clouds to pull the cache settings, since they are global (yet, we'll go back and fix this in sdk) If it's None, just use get_all and grab the first one. * Fix openstack inventory plugin for API changes The inventory plugin api grew a self.cache that wasn't there when we first wrote it. There's also a need to pull in the documentation fragments so that we have the cache parameters. --- lib/ansible/plugins/inventory/openstack.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/inventory/openstack.py b/lib/ansible/plugins/inventory/openstack.py index c3b5abcb8ad..bd1e303e8cc 100644 --- a/lib/ansible/plugins/inventory/openstack.py +++ b/lib/ansible/plugins/inventory/openstack.py @@ -15,6 +15,9 @@ DOCUMENTATION = ''' - Marco Vito Moscaritolo - Jesse Keating short_description: OpenStack inventory source + extends_documentation_fragment: + - inventory_cache + - constructed description: - Get inventory hosts from OpenStack clouds - Uses openstack.(yml|yaml) YAML configuration file to configure the inventory plugin @@ -146,10 +149,12 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): if 'clouds' in self._config_data: self._config_data = {} + if cache: + cache = self.get_option('cache') source_data = None - if cache and cache_key in self._cache: + if cache: try: - source_data = self._cache[cache_key] + source_data = self.cache.get(cache_key) except KeyError: pass @@ -185,7 +190,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): source_data = cloud_inventory.list_hosts( expand=expand_hostvars, fail_on_cloud_config=fail_on_errors) - self._cache[cache_key] = source_data + self.cache.set(cache_key, source_data) self._populate_from_source(source_data)