|
|
@ -46,6 +46,7 @@ class Inventory(object):
|
|
|
|
# 'parser', '_vars_per_host', '_vars_per_group', '_hosts_cache', '_groups_list',
|
|
|
|
# 'parser', '_vars_per_host', '_vars_per_group', '_hosts_cache', '_groups_list',
|
|
|
|
# '_pattern_cache', '_vault_password', '_vars_plugins', '_playbook_basedir']
|
|
|
|
# '_pattern_cache', '_vault_password', '_vars_plugins', '_playbook_basedir']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOCALHOST_ALIASES = frozenset(('localhost', '127.0.0.1', '::1'))
|
|
|
|
def __init__(self, loader, variable_manager, host_list=C.DEFAULT_HOST_LIST):
|
|
|
|
def __init__(self, loader, variable_manager, host_list=C.DEFAULT_HOST_LIST):
|
|
|
|
|
|
|
|
|
|
|
|
# the host file file, or script path, or list of hosts
|
|
|
|
# the host file file, or script path, or list of hosts
|
|
|
@ -368,7 +369,7 @@ class Inventory(object):
|
|
|
|
for host in matching_hosts:
|
|
|
|
for host in matching_hosts:
|
|
|
|
__append_host_to_results(host)
|
|
|
|
__append_host_to_results(host)
|
|
|
|
|
|
|
|
|
|
|
|
if pattern in ["localhost", "127.0.0.1", "::1"] and len(results) == 0:
|
|
|
|
if pattern in self.LOCALHOST_ALIASES and len(results) == 0:
|
|
|
|
new_host = self._create_implicit_localhost(pattern)
|
|
|
|
new_host = self._create_implicit_localhost(pattern)
|
|
|
|
results.append(new_host)
|
|
|
|
results.append(new_host)
|
|
|
|
return results
|
|
|
|
return results
|
|
|
@ -401,12 +402,15 @@ class Inventory(object):
|
|
|
|
def get_host(self, hostname):
|
|
|
|
def get_host(self, hostname):
|
|
|
|
if hostname not in self._hosts_cache:
|
|
|
|
if hostname not in self._hosts_cache:
|
|
|
|
self._hosts_cache[hostname] = self._get_host(hostname)
|
|
|
|
self._hosts_cache[hostname] = self._get_host(hostname)
|
|
|
|
|
|
|
|
if hostname in self.LOCALHOST_ALIASES:
|
|
|
|
|
|
|
|
for host in self.LOCALHOST_ALIASES.difference((hostname,)):
|
|
|
|
|
|
|
|
self._hosts_cache[host] = self._hosts_cache[hostname]
|
|
|
|
return self._hosts_cache[hostname]
|
|
|
|
return self._hosts_cache[hostname]
|
|
|
|
|
|
|
|
|
|
|
|
def _get_host(self, hostname):
|
|
|
|
def _get_host(self, hostname):
|
|
|
|
if hostname in ['localhost', '127.0.0.1', '::1']:
|
|
|
|
if hostname in self.LOCALHOST_ALIASES:
|
|
|
|
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', '::1']:
|
|
|
|
if host.name in self.LOCALHOST_ALIASES:
|
|
|
|
return host
|
|
|
|
return host
|
|
|
|
return self._create_implicit_localhost(hostname)
|
|
|
|
return self._create_implicit_localhost(hostname)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -502,7 +506,7 @@ class Inventory(object):
|
|
|
|
""" return a list of hostnames for a pattern """
|
|
|
|
""" return a list of hostnames for a pattern """
|
|
|
|
|
|
|
|
|
|
|
|
result = [ h for h in self.get_hosts(pattern) ]
|
|
|
|
result = [ h for h in self.get_hosts(pattern) ]
|
|
|
|
if len(result) == 0 and pattern in ["localhost", "127.0.0.1", "::1"]:
|
|
|
|
if len(result) == 0 and pattern in self.LOCALHOST_ALIASES:
|
|
|
|
result = [pattern]
|
|
|
|
result = [pattern]
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|