mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
ca139a5855
commit
f955d9db6a
1 changed files with 13 additions and 9 deletions
|
@ -249,6 +249,17 @@ class Inventory(object):
|
|||
else:
|
||||
return [ hosts[left] ]
|
||||
|
||||
def _create_implicit_localhost(self, pattern):
|
||||
new_host = Host(pattern)
|
||||
new_host.set_variable("ansible_python_interpreter", sys.executable)
|
||||
new_host.set_variable("ansible_connection", "local")
|
||||
ungrouped = self.get_group("ungrouped")
|
||||
if ungrouped is None:
|
||||
self.add_group(Group('ungrouped'))
|
||||
ungrouped = self.get_group('ungrouped')
|
||||
ungrouped.add_host(new_host)
|
||||
return new_host
|
||||
|
||||
def _hosts_in_unenumerated_pattern(self, pattern):
|
||||
""" Get all host names matching the pattern """
|
||||
|
||||
|
@ -268,15 +279,7 @@ class Inventory(object):
|
|||
hostnames.add(host.name)
|
||||
|
||||
if pattern in ["localhost", "127.0.0.1"] and len(results) == 0:
|
||||
new_host = Host(pattern)
|
||||
new_host.set_variable("ansible_python_interpreter", sys.executable)
|
||||
new_host.set_variable("ansible_connection", "local")
|
||||
ungrouped = self.get_group("ungrouped")
|
||||
if ungrouped is None:
|
||||
self.add_group(Group('ungrouped'))
|
||||
ungrouped = self.get_group('ungrouped')
|
||||
|
||||
ungrouped.add_host(new_host)
|
||||
new_host = self._create_implicit_localhost(pattern)
|
||||
results.append(new_host)
|
||||
return results
|
||||
|
||||
|
@ -319,6 +322,7 @@ class Inventory(object):
|
|||
for host in self.get_group('all').get_hosts():
|
||||
if host.name in ['localhost', '127.0.0.1']:
|
||||
return host
|
||||
return self._create_implicit_localhost(hostname)
|
||||
else:
|
||||
for group in self.groups:
|
||||
for host in group.get_hosts():
|
||||
|
|
Loading…
Reference in a new issue