Browse code

deal with other 'ungrouped' corner cases

(cherry picked from commit 2d9bf888970708765703150313fd2e4b3f8905a0)

Brian Coca authored on 2017/03/10 10:11:37
Showing 1 changed files
... ...
@@ -175,9 +175,16 @@ class Inventory(object):
175 175
             if all not in mygroups:
176 176
                 all.add_host(host)
177 177
 
178
-            # clear ungrouped of any incorrectly stored by parser
179
-            if len(mygroups) > 2 and ungrouped in mygroups:
180
-                host.remove_group(ungrouped)
178
+            if ungrouped in mygroups:
179
+                # clear ungrouped of any incorrectly stored by parser
180
+                if set(mygroups).difference(set([all, ungrouped])):
181
+                    host.remove_group(ungrouped)
182
+            else:
183
+                # add ungrouped hosts to ungrouped
184
+                length = len(mygroups)
185
+                if length == 0 or (length == 1 and all in mygroups):
186
+                    ungrouped.add_host(host)
187
+
181 188
 
182 189
     def _match(self, str, pattern_str):
183 190
         try: