From 37b91c7b81b09cf768d538936a9063bb70c8e7a6 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Wed, 17 Oct 2012 22:42:25 +0200 Subject: [PATCH] Fix ansible_ssh_host after 339c05bb --- lib/ansible/runner/__init__.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 1cd16c37c0..e556081dc2 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -382,31 +382,24 @@ class Runner(object): conn = None actual_host = host + actual_port = port try: + alternative_host = inject.get('ansible_ssh_host', None) + if alternative_host is not None: + actual_host = alternative_host + delegate_to = inject.get('delegate_to', None) # the delegated host may have different SSH port configured, etc # and we need to transfer those, and only those, variables if delegate_to is not None: - delegate_to = utils.template(self.basedir, delegate_to, inject) - delegate_vars = {} - try: - delegate_vars = inject['hostvars'][delegate_to] - for (k,v) in delegate_vars.iteritems(): - if k.startswith('ansible_ssh_'): - inject[k] = v - except errors.AnsibleError: - # host not listed in inventory, it's ok - pass - - # the host record may just be an alias in case of tunnels - alternative_host = inject.get('ansible_ssh_host', None) - if delegate_to is not None and not alternative_host: - actual_host = delegate_to + delegate_to = utils.template(self.basedir, delegate_to, inject) + actual_host = inject['hostvars'][delegate_to].get('ansible_ssh_host', delegate_to) + actual_port = inject['hostvars'][delegate_to].get('ansible_ssh_port', port) # connect - conn = self.connector.connect(actual_host, port) + conn = self.connector.connect(actual_host, actual_port) if delegate_to is not None or alternative_host is not None: conn._delegate_for = host