From de2746ae86b51d2b0f764a7a64e65196f51ec1aa Mon Sep 17 00:00:00 2001 From: Chris Church Date: Sun, 23 Nov 2014 21:49:33 -0500 Subject: [PATCH] Set delegate on connection prior to calling connect. --- lib/ansible/runner/__init__.py | 6 ++++-- lib/ansible/runner/connection.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 0d16746255..87f10dd8a1 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -931,9 +931,11 @@ class Runner(object): return ReturnData(host=host, comm_ok=False, result=result) try: - conn = self.connector.connect(actual_host, actual_port, actual_user, actual_pass, actual_transport, actual_private_key_file) if self.delegate_to or host != actual_host: - conn.delegate = host + delegate_host = host + else: + delegate_host = None + conn = self.connector.connect(actual_host, actual_port, actual_user, actual_pass, actual_transport, actual_private_key_file, delegate_host) default_shell = getattr(conn, 'default_shell', '') shell_type = inject.get('ansible_shell_type') diff --git a/lib/ansible/runner/connection.py b/lib/ansible/runner/connection.py index bb50bf5531..2ea484f70b 100644 --- a/lib/ansible/runner/connection.py +++ b/lib/ansible/runner/connection.py @@ -31,10 +31,11 @@ class Connector(object): def __init__(self, runner): self.runner = runner - def connect(self, host, port, user, password, transport, private_key_file): + def connect(self, host, port, user, password, transport, private_key_file, delegate_host): conn = utils.plugins.connection_loader.get(transport, self.runner, host, port, user=user, password=password, private_key_file=private_key_file) if conn is None: raise AnsibleError("unsupported connection type: %s" % transport) + conn.delegate = delegate_host if private_key_file: # If private key is readable by user other than owner, flag an error st = None