From 5a9c7676620d4971eb6ce8d4014e3636b21e3f03 Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Fri, 16 Nov 2018 19:03:20 -0500 Subject: [PATCH] fix constructed functionality in openstack inventory plugin The compose, groups, and keyed_groups functionality of the openstack inventory plugin was broken: - the plugin was not passing the correct variables to the Constructable methods for compose and groups - the plugin was simply never calling the appropriate method for implementing keyed_groups This commit fixes both issues. --- lib/ansible/plugins/inventory/openstack.py | 8 ++++++-- test/units/plugins/inventory/test_openstack.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/inventory/openstack.py b/lib/ansible/plugins/inventory/openstack.py index 74fb68ee24c..9c9a1e03001 100644 --- a/lib/ansible/plugins/inventory/openstack.py +++ b/lib/ansible/plugins/inventory/openstack.py @@ -240,7 +240,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): # create composite vars self._set_composite_vars( - self._config_data.get('compose'), hostvars, host) + self._config_data.get('compose'), hostvars[host], host) # actually update inventory for key in hostvars[host]: @@ -248,7 +248,11 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): # constructed groups based on conditionals self._add_host_to_composed_groups( - self._config_data.get('groups'), hostvars, host) + self._config_data.get('groups'), hostvars[host], host) + + # constructed groups based on jinja expressions + self._add_host_to_keyed_groups( + self._config_data.get('keyed_groups'), hostvars[host], host) for group_name, group_hosts in groups.items(): self.inventory.add_group(group_name) diff --git a/test/units/plugins/inventory/test_openstack.py b/test/units/plugins/inventory/test_openstack.py index a9cbaba0849..fec7ae580c4 100644 --- a/test/units/plugins/inventory/test_openstack.py +++ b/test/units/plugins/inventory/test_openstack.py @@ -68,7 +68,7 @@ def inventory(): return inventory -def test_simpel_groups(inventory): +def test_simple_groups(inventory): inventory._set_variables(hostvars, {}) groups = inventory.inventory.get_groups_dict() assert 'testgroup' in groups