From 61e726fe82dc184bec0d781463ae7f971f6c364f Mon Sep 17 00:00:00 2001 From: Timothy Appnel Date: Fri, 13 Sep 2013 23:56:25 -0400 Subject: [PATCH] Fix to local delegate_to override and proper sudo handling from @smoothify --- lib/ansible/runner/action_plugins/synchronize.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/ansible/runner/action_plugins/synchronize.py b/lib/ansible/runner/action_plugins/synchronize.py index 87264475da..fc440dd35f 100644 --- a/lib/ansible/runner/action_plugins/synchronize.py +++ b/lib/ansible/runner/action_plugins/synchronize.py @@ -37,6 +37,11 @@ class ActionModule(object): ''' Always default to localhost as delegate if None defined ''' if inject.get('delegate_to') is None: inject['delegate_to'] = '127.0.0.1' + inject['ansible_connection'] = 'local' + # If sudo is active, disable from the connection set self.sudo to True. + if self.runner.sudo: + self.runner.sudo = False + self.sudo = True def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **kwargs): @@ -76,7 +81,13 @@ class ActionModule(object): if 'mode' in options: del options['mode'] - # run the synchronize module + rsync_path = options.get('rsync_path', None) + if not rsync_path and self.sudo: + rsync_path = 'sudo rsync' + + # make sure rsync path is quoted. + if rsync_path: + options['rsync_path'] = '"' + rsync_path + '"' self.runner.module_args = ' '.join(['%s=%s' % (k, v) for (k, v) in options.items()])