Fix logic surrounding copy and remote_src, remote_src is preferred, make copy action plugin only. Fixes #23591 (#24732)

This commit is contained in:
Matt Martz 2017-05-22 19:19:56 -05:00 committed by Toshio Kuratomi
parent f5fd32eae6
commit 4ac135c1b5
2 changed files with 4 additions and 7 deletions

View file

@ -770,7 +770,6 @@ def main():
src = dict(required=True, type='path'), src = dict(required=True, type='path'),
original_basename = dict(required=False, type='str'), # used to handle 'dest is a directory' via template, a slight hack original_basename = dict(required=False, type='str'), # used to handle 'dest is a directory' via template, a slight hack
dest = dict(required=True, type='path'), dest = dict(required=True, type='path'),
copy = dict(required=False, default=True, type='bool'),
remote_src = dict(required=False, default=False, type='bool'), remote_src = dict(required=False, default=False, type='bool'),
creates = dict(required=False, type='path'), creates = dict(required=False, type='path'),
list_files = dict(required=False, default=False, type='bool'), list_files = dict(required=False, default=False, type='bool'),
@ -780,21 +779,19 @@ def main():
validate_certs = dict(required=False, default=True, type='bool'), validate_certs = dict(required=False, default=True, type='bool'),
), ),
add_file_common_args = True, add_file_common_args = True,
mutually_exclusive = [("copy", "remote_src"),],
# check-mode only works for zip files, we cover that later # check-mode only works for zip files, we cover that later
supports_check_mode = True, supports_check_mode = True,
) )
src = module.params['src'] src = module.params['src']
dest = module.params['dest'] dest = module.params['dest']
copy = module.params['copy']
remote_src = module.params['remote_src'] remote_src = module.params['remote_src']
file_args = module.load_file_common_arguments(module.params) file_args = module.load_file_common_arguments(module.params)
# did tar file arrive? # did tar file arrive?
if not os.path.exists(src): if not os.path.exists(src):
if not remote_src and copy: if not remote_src:
module.fail_json(msg="Source '%s' failed to transfer" % src) module.fail_json(msg="Source '%s' failed to transfer" % src)
# If copy=false, and src= contains ://, try and download the file to a temp directory. # If remote_src=true, and src= contains ://, try and download the file to a temp directory.
elif '://' in src: elif '://' in src:
tempdir = os.path.dirname(os.path.realpath(__file__)) tempdir = os.path.dirname(os.path.realpath(__file__))
package = os.path.join(tempdir, str(src.rsplit('/', 1)[1])) package = os.path.join(tempdir, str(src.rsplit('/', 1)[1]))

View file

@ -53,7 +53,7 @@ class ActionModule(ActionBase):
return result return result
# We will take the information from copy and store it in # We will take the information from copy and store it in
# the remote_src var to use later in this file. # the remote_src var to use later in this file.
remote_src = not boolean(self._task.args.get('copy')) self._task.args['remote_src'] = remote_src = not boolean(self._task.args.pop('copy'))
if source is None or dest is None: if source is None or dest is None:
result['failed'] = True result['failed'] = True
@ -128,7 +128,7 @@ class ActionModule(ActionBase):
) )
# remove action plugin only key # remove action plugin only key
for key in ('remote_src', 'decrypt'): for key in ('decrypt',):
if key in new_module_args: if key in new_module_args:
del new_module_args[key] del new_module_args[key]