summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <brian.coca+git@gmail.com>2017-03-07 11:57:20 -0500
committerBrian Coca <bcoca@users.noreply.github.com>2017-03-07 12:49:24 -0500
commitc4cff44e772e8b4631386243169d164bc0b0937c (patch)
tree0a64123e98830dce2a2653e018e896deb07fcd07
parent20bf02f6b96356ab5fe68578a3af9462b4ca42a5 (diff)
downloadansible-c4cff44e772e8b4631386243169d164bc0b0937c.tar.gz
fix 'ungrouped' issue with some inventory formats
-rw-r--r--lib/ansible/inventory/__init__.py5
-rw-r--r--lib/ansible/inventory/group.py6
-rw-r--r--lib/ansible/inventory/host.py4
3 files changed, 15 insertions, 0 deletions
diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py
index 1f0317c454..fc808e3ca3 100644
--- a/lib/ansible/inventory/__init__.py
+++ b/lib/ansible/inventory/__init__.py
@@ -170,6 +170,11 @@ class Inventory(object):
host.vars = combine_vars(host.vars, self.get_host_variables(host.name))
self.get_host_vars(host)
+ # clear ungrouped of any incorrectly stored by parser
+ mygroups = host.get_groups()
+ if len(mygroups) > 2 and ungrouped in mygroups:
+ host.remove_group(ungrouped)
+
def _match(self, str, pattern_str):
try:
if pattern_str.startswith('~'):
diff --git a/lib/ansible/inventory/group.py b/lib/ansible/inventory/group.py
index a6ab35c3e9..73d432e545 100644
--- a/lib/ansible/inventory/group.py
+++ b/lib/ansible/inventory/group.py
@@ -114,6 +114,12 @@ class Group:
host.add_group(self)
self.clear_hosts_cache()
+ def remove_host(self, host):
+
+ self.hosts.remove(host)
+ host.remove_group(self)
+ self.clear_hosts_cache()
+
def set_variable(self, key, value):
self.vars[key] = value
diff --git a/lib/ansible/inventory/host.py b/lib/ansible/inventory/host.py
index 8d0fc9a52c..3902471e54 100644
--- a/lib/ansible/inventory/host.py
+++ b/lib/ansible/inventory/host.py
@@ -110,6 +110,10 @@ class Host:
self.groups.append(group)
+ def remove_group(self, group):
+
+ self.groups.remove(group)
+
def set_variable(self, key, value):
self.vars[key]=value