diff --git a/lib/ansible/inventory/group.py b/lib/ansible/inventory/group.py index 0933e1ab5d0..4847e6fbd82 100644 --- a/lib/ansible/inventory/group.py +++ b/lib/ansible/inventory/group.py @@ -18,7 +18,6 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type from ansible.errors import AnsibleError -from ansible.utils.vars import combine_vars class Group: @@ -31,7 +30,7 @@ class Group: self.depth = 0 self.name = name self.hosts = [] - self._hosts = set() + self._hosts = None self.vars = {} self.child_groups = [] self.parent_groups = [] @@ -72,9 +71,8 @@ class Group: self.name = data.get('name') self.vars = data.get('vars', dict()) self.depth = data.get('depth', 0) - self.hosts = data.get('hosts', {}) - - self._hosts = set(self.hosts) + self.hosts = data.get('hosts', []) + self._hosts = None parent_groups = data.get('parent_groups', []) for parent_data in parent_groups: @@ -82,6 +80,12 @@ class Group: g.deserialize(parent_data) self.parent_groups.append(g) + @property + def host_names(self): + if self._hosts is None: + self._hosts = set(self.hosts) + return self._hosts + def get_name(self): return self.name @@ -119,7 +123,7 @@ class Group: raise AnsibleError("The group named '%s' has a recursive dependency loop." % self.name) def add_host(self, host): - if host.name not in self._hosts: + if host.name not in self.host_names: self.hosts.append(host) self._hosts.add(host.name) host.add_group(self) @@ -127,7 +131,7 @@ class Group: def remove_host(self, host): - if host.name in self._hosts: + if host.name in self.host_names: self.hosts.remove(host) self._hosts.remove(host.name) host.remove_group(self)