From 5626efba7e22562de19f5fd29b4778d0c020fd9d Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Mon, 2 Dec 2013 19:51:10 -0600 Subject: [PATCH 1/3] Optionally unarchive a file already on the remote machine --- lib/ansible/runner/action_plugins/unarchive.py | 17 ++++++++++------- library/files/unarchive | 12 +++++++++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/ansible/runner/action_plugins/unarchive.py b/lib/ansible/runner/action_plugins/unarchive.py index f0b9dee945..16f4a8e46f 100644 --- a/lib/ansible/runner/action_plugins/unarchive.py +++ b/lib/ansible/runner/action_plugins/unarchive.py @@ -48,25 +48,28 @@ class ActionModule(object): options.update(utils.parse_kv(module_args)) source = options.get('src', None) dest = options.get('dest', None) + copy = options.get('copy', True) if source is None or dest is None: result=dict(failed=True, msg="src (or content) and dest are required") return ReturnData(conn=conn, result=result) source = template.template(self.runner.basedir, source, inject) - if '_original_file' in inject: - source = utils.path_dwim_relative(inject['_original_file'], 'files', source, self.runner.basedir) - else: - source = utils.path_dwim(self.runner.basedir, source) + if copy: + if '_original_file' in inject: + source = utils.path_dwim_relative(inject['_original_file'], 'files', source, self.runner.basedir) + else: + source = utils.path_dwim(self.runner.basedir, source) remote_md5 = self.runner._remote_md5(conn, tmp, dest) if remote_md5 != '3': result = dict(failed=True, msg="dest must be an existing dir") return ReturnData(conn=conn, result=result) - # transfer the file to a remote tmp location - tmp_src = tmp + 'source' - conn.put_file(source, tmp_src) + if copy: + # transfer the file to a remote tmp location + tmp_src = tmp + 'source' + conn.put_file(source, tmp_src) # handle diff mode client side # handle check mode client side diff --git a/library/files/unarchive b/library/files/unarchive index d85ae3cc59..02c94cdb41 100644 --- a/library/files/unarchive +++ b/library/files/unarchive @@ -37,6 +37,12 @@ options: - Remote absolute path where the archive should be unpacked required: true default: null + copy: + description: + - Should the file be copied from the local to the remote machine? + required: false + choices: [ "yes", "no" ] + default: "yes" author: Dylan Martin todo: - detect changed/unchanged for .zip files @@ -153,6 +159,7 @@ def main(): src = dict(required=True), original_basename = dict(required=False), # used to handle 'dest is a directory' via template, a slight hack dest = dict(required=True), + copy = dict(default=True, type='bool'), ), add_file_common_args=True, ) @@ -162,7 +169,10 @@ def main(): # did tar file arrive? if not os.path.exists(src): - module.fail_json(msg="Source '%s' failed to transfer" % (src)) + if copy: + module.fail_json(msg="Source '%s' failed to transfer" % (src)) + else: + module.fail_json(msg="Source '%s' does not exist" % (src)) if not os.access(src, os.R_OK): module.fail_json(msg="Source '%s' not readable" % (src)) From 4afcd504874c249e23a298a5fd2c75bb374b7b41 Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Tue, 3 Dec 2013 18:46:37 -0600 Subject: [PATCH 2/3] properly convert arg into boolean --- lib/ansible/runner/action_plugins/unarchive.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/runner/action_plugins/unarchive.py b/lib/ansible/runner/action_plugins/unarchive.py index 16f4a8e46f..1ae9f916e9 100644 --- a/lib/ansible/runner/action_plugins/unarchive.py +++ b/lib/ansible/runner/action_plugins/unarchive.py @@ -48,7 +48,7 @@ class ActionModule(object): options.update(utils.parse_kv(module_args)) source = options.get('src', None) dest = options.get('dest', None) - copy = options.get('copy', True) + copy = utils.boolean(options.get('copy', 'yes')) if source is None or dest is None: result=dict(failed=True, msg="src (or content) and dest are required") From 58acd8cce1e10399bf730f638893cbae7f7544f0 Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Tue, 3 Dec 2013 18:59:50 -0600 Subject: [PATCH 3/3] If there is no tmp_src, don't modify the args --- lib/ansible/runner/action_plugins/unarchive.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/runner/action_plugins/unarchive.py b/lib/ansible/runner/action_plugins/unarchive.py index 1ae9f916e9..8a4cb657eb 100644 --- a/lib/ansible/runner/action_plugins/unarchive.py +++ b/lib/ansible/runner/action_plugins/unarchive.py @@ -74,7 +74,10 @@ class ActionModule(object): # handle diff mode client side # handle check mode client side # fix file permissions when the copy is done as a different user - if self.runner.sudo and self.runner.sudo_user != 'root': - self.runner._low_level_exec_command(conn, "chmod a+r %s" % tmp_src, tmp) - module_args = "%s src=%s original_basename=%s" % (module_args, pipes.quote(tmp_src), pipes.quote(os.path.basename(source))) + if copy: + if self.runner.sudo and self.runner.sudo_user != 'root': + self.runner._low_level_exec_command(conn, "chmod a+r %s" % tmp_src, tmp) + module_args = "%s src=%s original_basename=%s" % (module_args, pipes.quote(tmp_src), pipes.quote(os.path.basename(source))) + else: + module_args = "%s original_basename=%s" % (module_args, pipes.quote(os.path.basename(source))) return self.runner._execute_module(conn, tmp, 'unarchive', module_args, inject=inject, complex_args=complex_args)