Optionally unarchive a file already on the remote machine
This commit is contained in:
parent
9101c2af98
commit
5626efba7e
2 changed files with 21 additions and 8 deletions
|
@ -48,12 +48,14 @@ class ActionModule(object):
|
||||||
options.update(utils.parse_kv(module_args))
|
options.update(utils.parse_kv(module_args))
|
||||||
source = options.get('src', None)
|
source = options.get('src', None)
|
||||||
dest = options.get('dest', None)
|
dest = options.get('dest', None)
|
||||||
|
copy = options.get('copy', True)
|
||||||
|
|
||||||
if source is None or dest is None:
|
if source is None or dest is None:
|
||||||
result=dict(failed=True, msg="src (or content) and dest are required")
|
result=dict(failed=True, msg="src (or content) and dest are required")
|
||||||
return ReturnData(conn=conn, result=result)
|
return ReturnData(conn=conn, result=result)
|
||||||
|
|
||||||
source = template.template(self.runner.basedir, source, inject)
|
source = template.template(self.runner.basedir, source, inject)
|
||||||
|
if copy:
|
||||||
if '_original_file' in inject:
|
if '_original_file' in inject:
|
||||||
source = utils.path_dwim_relative(inject['_original_file'], 'files', source, self.runner.basedir)
|
source = utils.path_dwim_relative(inject['_original_file'], 'files', source, self.runner.basedir)
|
||||||
else:
|
else:
|
||||||
|
@ -64,6 +66,7 @@ class ActionModule(object):
|
||||||
result = dict(failed=True, msg="dest must be an existing dir")
|
result = dict(failed=True, msg="dest must be an existing dir")
|
||||||
return ReturnData(conn=conn, result=result)
|
return ReturnData(conn=conn, result=result)
|
||||||
|
|
||||||
|
if copy:
|
||||||
# transfer the file to a remote tmp location
|
# transfer the file to a remote tmp location
|
||||||
tmp_src = tmp + 'source'
|
tmp_src = tmp + 'source'
|
||||||
conn.put_file(source, tmp_src)
|
conn.put_file(source, tmp_src)
|
||||||
|
|
|
@ -37,6 +37,12 @@ options:
|
||||||
- Remote absolute path where the archive should be unpacked
|
- Remote absolute path where the archive should be unpacked
|
||||||
required: true
|
required: true
|
||||||
default: null
|
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
|
author: Dylan Martin
|
||||||
todo:
|
todo:
|
||||||
- detect changed/unchanged for .zip files
|
- detect changed/unchanged for .zip files
|
||||||
|
@ -153,6 +159,7 @@ def main():
|
||||||
src = dict(required=True),
|
src = dict(required=True),
|
||||||
original_basename = dict(required=False), # used to handle 'dest is a directory' via template, a slight hack
|
original_basename = dict(required=False), # used to handle 'dest is a directory' via template, a slight hack
|
||||||
dest = dict(required=True),
|
dest = dict(required=True),
|
||||||
|
copy = dict(default=True, type='bool'),
|
||||||
),
|
),
|
||||||
add_file_common_args=True,
|
add_file_common_args=True,
|
||||||
)
|
)
|
||||||
|
@ -162,7 +169,10 @@ def main():
|
||||||
|
|
||||||
# did tar file arrive?
|
# did tar file arrive?
|
||||||
if not os.path.exists(src):
|
if not os.path.exists(src):
|
||||||
|
if copy:
|
||||||
module.fail_json(msg="Source '%s' failed to transfer" % (src))
|
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):
|
if not os.access(src, os.R_OK):
|
||||||
module.fail_json(msg="Source '%s' not readable" % (src))
|
module.fail_json(msg="Source '%s' not readable" % (src))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue