From 5b0d8ab86870fdc3642891acc183253b396a6e00 Mon Sep 17 00:00:00 2001 From: Izuke <37222566+Ikuze@users.noreply.github.com> Date: Mon, 19 Mar 2018 11:39:29 -0700 Subject: [PATCH] Fixes #32146 Fixes reconcile inventory to correctly remove hosts from ungrouped (cherry picked from commit e02c72d856ac10c6534a1731db92360cd132f06e) --- lib/ansible/inventory/data.py | 2 +- test/units/plugins/inventory/test_inventory.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/inventory/data.py b/lib/ansible/inventory/data.py index 04308a0ed91..dc730ff6065 100644 --- a/lib/ansible/inventory/data.py +++ b/lib/ansible/inventory/data.py @@ -128,7 +128,7 @@ class InventoryData(object): if self.groups['ungrouped'] in mygroups: # clear ungrouped of any incorrectly stored by parser if set(mygroups).difference(set([self.groups['all'], self.groups['ungrouped']])): - host.remove_group(self.groups['ungrouped']) + self.groups['ungrouped'].remove_host(host) elif not host.implicit: # add ungrouped hosts to ungrouped, except implicit diff --git a/test/units/plugins/inventory/test_inventory.py b/test/units/plugins/inventory/test_inventory.py index ab6bdac84fd..394ae53df76 100644 --- a/test/units/plugins/inventory/test_inventory.py +++ b/test/units/plugins/inventory/test_inventory.py @@ -198,6 +198,6 @@ class TestInventoryPlugins(unittest.TestCase): all_hosts = set(host.name for host in inventory.groups['all'].get_hosts()) self.assertEqual(set(['host1', 'host2', 'host3', 'host4', 'host5']), all_hosts) ungrouped_hosts = set(host.name for host in inventory.groups['ungrouped'].get_hosts()) - self.assertEqual(set(['host1', 'host2', 'host3']), ungrouped_hosts) + self.assertEqual(set(['host1', 'host2']), ungrouped_hosts) servers_hosts = set(host.name for host in inventory.groups['servers'].get_hosts()) self.assertEqual(set(['host3', 'host4', 'host5']), servers_hosts)