mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 14:41:23 -07:00
Mark implicitly hosts as such and exclude them from the all group
Fixes #16059
This commit is contained in:
parent
a7d7cdae1f
commit
879dc3a687
3 changed files with 12 additions and 0 deletions
|
@ -445,10 +445,14 @@ class Inventory(object):
|
||||||
for group in groups.values():
|
for group in groups.values():
|
||||||
if pattern == 'all':
|
if pattern == 'all':
|
||||||
for host in group.get_hosts():
|
for host in group.get_hosts():
|
||||||
|
if host.implicit:
|
||||||
|
continue
|
||||||
__append_host_to_results(host)
|
__append_host_to_results(host)
|
||||||
else:
|
else:
|
||||||
if self._match(group.name, pattern) and group.name not in ('all', 'ungrouped'):
|
if self._match(group.name, pattern) and group.name not in ('all', 'ungrouped'):
|
||||||
for host in group.get_hosts():
|
for host in group.get_hosts():
|
||||||
|
if host.implicit:
|
||||||
|
continue
|
||||||
__append_host_to_results(host)
|
__append_host_to_results(host)
|
||||||
else:
|
else:
|
||||||
matching_hosts = self._match_list(group.get_hosts(), 'name', pattern)
|
matching_hosts = self._match_list(group.get_hosts(), 'name', pattern)
|
||||||
|
@ -463,6 +467,7 @@ class Inventory(object):
|
||||||
def _create_implicit_localhost(self, pattern):
|
def _create_implicit_localhost(self, pattern):
|
||||||
new_host = Host(pattern)
|
new_host = Host(pattern)
|
||||||
new_host.address = "127.0.0.1"
|
new_host.address = "127.0.0.1"
|
||||||
|
new_host.implicit = True
|
||||||
new_host.vars = self.get_host_vars(new_host)
|
new_host.vars = self.get_host_vars(new_host)
|
||||||
new_host.set_variable("ansible_connection", "local")
|
new_host.set_variable("ansible_connection", "local")
|
||||||
if "ansible_python_interpreter" not in new_host.vars:
|
if "ansible_python_interpreter" not in new_host.vars:
|
||||||
|
|
|
@ -140,10 +140,14 @@ class Group:
|
||||||
for kk in kid_hosts:
|
for kk in kid_hosts:
|
||||||
if kk not in seen:
|
if kk not in seen:
|
||||||
seen[kk] = 1
|
seen[kk] = 1
|
||||||
|
if self.name == 'all' and kk.implicit:
|
||||||
|
continue
|
||||||
hosts.append(kk)
|
hosts.append(kk)
|
||||||
for mine in self.hosts:
|
for mine in self.hosts:
|
||||||
if mine not in seen:
|
if mine not in seen:
|
||||||
seen[mine] = 1
|
seen[mine] = 1
|
||||||
|
if self.name == 'all' and mine.implicit:
|
||||||
|
continue
|
||||||
hosts.append(mine)
|
hosts.append(mine)
|
||||||
return hosts
|
return hosts
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ class Host:
|
||||||
uuid=self._uuid,
|
uuid=self._uuid,
|
||||||
gathered_facts=self._gathered_facts,
|
gathered_facts=self._gathered_facts,
|
||||||
groups=groups,
|
groups=groups,
|
||||||
|
implicit=self.implicit,
|
||||||
)
|
)
|
||||||
|
|
||||||
def deserialize(self, data):
|
def deserialize(self, data):
|
||||||
|
@ -69,6 +70,7 @@ class Host:
|
||||||
self.vars = data.get('vars', dict())
|
self.vars = data.get('vars', dict())
|
||||||
self.address = data.get('address', '')
|
self.address = data.get('address', '')
|
||||||
self._uuid = data.get('uuid', uuid.uuid4())
|
self._uuid = data.get('uuid', uuid.uuid4())
|
||||||
|
self.implicit= data.get('implicit', False)
|
||||||
|
|
||||||
groups = data.get('groups', [])
|
groups = data.get('groups', [])
|
||||||
for group_data in groups:
|
for group_data in groups:
|
||||||
|
@ -89,6 +91,7 @@ class Host:
|
||||||
|
|
||||||
self._gathered_facts = False
|
self._gathered_facts = False
|
||||||
self._uuid = uuid.uuid4()
|
self._uuid = uuid.uuid4()
|
||||||
|
self.implicit = False
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.get_name()
|
return self.get_name()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue