From 2e39070ffd6f061723f0e7831aa6d611cdc4f6cc Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Thu, 8 Dec 2016 13:59:23 -0500 Subject: [PATCH 1/2] Look at 'ansible_host' for callbacks, not just 'ansible_ssh_host'. --- awx/api/views.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/awx/api/views.py b/awx/api/views.py index e803a64b3f..6e0a730472 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -2564,20 +2564,22 @@ class JobTemplateCallback(GenericAPIView): # Next, try matching based on name or ansible_ssh_host variable. matches = set() for host in hosts: - ansible_ssh_host = host.variables_dict.get('ansible_ssh_host', '') - if ansible_ssh_host in remote_hosts: - matches.add(host) - if host.name != ansible_ssh_host and host.name in remote_hosts: - matches.add(host) + for host_var in ['ansible_ssh_host', 'ansible_host']: + ansible_host = host.variables_dict.get(host_var, '') + if ansible_host in remote_hosts: + matches.add(host) + if host.name != ansible_host and host.name in remote_hosts: + matches.add(host) if len(matches) == 1: return matches # Try to resolve forward addresses for each host to find matches. for host in hosts: hostnames = set([host.name]) - ansible_ssh_host = host.variables_dict.get('ansible_ssh_host', '') - if ansible_ssh_host: - hostnames.add(ansible_ssh_host) + for host_var in ['ansible_ssh_host', 'ansible_host']: + ansible_host = host.variables_dict.get(host_var, '') + if ansible_host: + hostnames.add(ansible_host) for hostname in hostnames: try: result = socket.getaddrinfo(hostname, None) From bf5479f6ba14beb55ea34bd8c6be77db84d1bfb7 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Thu, 8 Dec 2016 14:06:04 -0500 Subject: [PATCH 2/2] Tweak comment --- awx/api/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/api/views.py b/awx/api/views.py index 6e0a730472..b82cb424d6 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -2561,7 +2561,7 @@ class JobTemplateCallback(GenericAPIView): return set([hosts.get(name__in=remote_hosts)]) except (Host.DoesNotExist, Host.MultipleObjectsReturned): pass - # Next, try matching based on name or ansible_ssh_host variable. + # Next, try matching based on name or ansible_host variables. matches = set() for host in hosts: for host_var in ['ansible_ssh_host', 'ansible_host']: