diff options
| author | Brian Coca <bcoca@users.noreply.github.com> | 2017-10-03 11:59:05 -0400 |
|---|---|---|
| committer | Matt Clay <matt@mystile.com> | 2017-10-03 08:59:05 -0700 |
| commit | cf3414d7d7a02a785646b051bfc7f6f28d821c4e (patch) | |
| tree | d88635ecd4e5a13deda4ab21d31a14031bc8a5ae | |
| parent | 101377768bf12840fbb50a4fce4970cc851c8a37 (diff) | |
| download | ansible-cf3414d7d7a02a785646b051bfc7f6f28d821c4e.tar.gz | |
set _hosts on access if None (#31111)
set _hosts on access if None to bpyass srlz10n issues to fix #30903
| -rw-r--r-- | lib/ansible/inventory/group.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/ansible/inventory/group.py b/lib/ansible/inventory/group.py index 0933e1ab5d..4847e6fbd8 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) |
