mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
@@ -249,6 +249,17 @@ class Inventory(object):
|
|||||||
else:
|
else:
|
||||||
return [ hosts[left] ]
|
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):
|
def _hosts_in_unenumerated_pattern(self, pattern):
|
||||||
""" Get all host names matching the pattern """
|
""" Get all host names matching the pattern """
|
||||||
|
|
||||||
@@ -268,15 +279,7 @@ class Inventory(object):
|
|||||||
hostnames.add(host.name)
|
hostnames.add(host.name)
|
||||||
|
|
||||||
if pattern in ["localhost", "127.0.0.1"] and len(results) == 0:
|
if pattern in ["localhost", "127.0.0.1"] and len(results) == 0:
|
||||||
new_host = Host(pattern)
|
new_host = self._create_implicit_localhost(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)
|
|
||||||
results.append(new_host)
|
results.append(new_host)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@@ -319,6 +322,7 @@ class Inventory(object):
|
|||||||
for host in self.get_group('all').get_hosts():
|
for host in self.get_group('all').get_hosts():
|
||||||
if host.name in ['localhost', '127.0.0.1']:
|
if host.name in ['localhost', '127.0.0.1']:
|
||||||
return host
|
return host
|
||||||
|
return self._create_implicit_localhost(hostname)
|
||||||
else:
|
else:
|
||||||
for group in self.groups:
|
for group in self.groups:
|
||||||
for host in group.get_hosts():
|
for host in group.get_hosts():
|
||||||
|
|||||||
Reference in New Issue
Block a user