Merge pull request #4347 from wenottingham/hostvar

Look at 'ansible_host' for callbacks, not just 'ansible_ssh_host'. (#4346)
This commit is contained in:
Bill Nottingham
2016-12-08 18:42:34 -05:00
committed by GitHub

View File

@@ -2561,23 +2561,25 @@ class JobTemplateCallback(GenericAPIView):
return set([hosts.get(name__in=remote_hosts)]) return set([hosts.get(name__in=remote_hosts)])
except (Host.DoesNotExist, Host.MultipleObjectsReturned): except (Host.DoesNotExist, Host.MultipleObjectsReturned):
pass pass
# Next, try matching based on name or ansible_ssh_host variable. # Next, try matching based on name or ansible_host variables.
matches = set() matches = set()
for host in hosts: for host in hosts:
ansible_ssh_host = host.variables_dict.get('ansible_ssh_host', '') for host_var in ['ansible_ssh_host', 'ansible_host']:
if ansible_ssh_host in remote_hosts: ansible_host = host.variables_dict.get(host_var, '')
matches.add(host) if ansible_host in remote_hosts:
if host.name != ansible_ssh_host and host.name in remote_hosts: matches.add(host)
matches.add(host) if host.name != ansible_host and host.name in remote_hosts:
matches.add(host)
if len(matches) == 1: if len(matches) == 1:
return matches return matches
# Try to resolve forward addresses for each host to find matches. # Try to resolve forward addresses for each host to find matches.
for host in hosts: for host in hosts:
hostnames = set([host.name]) hostnames = set([host.name])
ansible_ssh_host = host.variables_dict.get('ansible_ssh_host', '') for host_var in ['ansible_ssh_host', 'ansible_host']:
if ansible_ssh_host: ansible_host = host.variables_dict.get(host_var, '')
hostnames.add(ansible_ssh_host) if ansible_host:
hostnames.add(ansible_host)
for hostname in hostnames: for hostname in hostnames:
try: try:
result = socket.getaddrinfo(hostname, None) result = socket.getaddrinfo(hostname, None)