Skip to content

Commit

Permalink
[aws_s3] Fix uploading src option on the target machine to a bucket (a…
Browse files Browse the repository at this point in the history
…nsible#39023)

* Fix backward compatibility for uploading src option on the target machine to a bucket

* Allow the module to handle errors for nonexistent files
  • Loading branch information
s-hertel authored and Timur Evdokimov committed Jun 26, 2018
1 parent 89d815a commit 8127e77
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/ansible/plugins/action/aws_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import os

from ansible.errors import AnsibleError, AnsibleAction, AnsibleActionFail
from ansible.errors import AnsibleError, AnsibleAction, AnsibleActionFail, AnsibleFileNotFound
from ansible.module_utils._text import to_text
from ansible.plugins.action import ActionBase

Expand All @@ -43,11 +43,17 @@ def run(self, tmp=None, task_vars=None):
new_module_args = self._task.args.copy()
if source:
source = os.path.expanduser(source)
try:
source = self._loader.get_real_file(self._find_needle('files', source))
new_module_args['src'] = source
except AnsibleError as e:
raise AnsibleActionFail(to_text(e))

# For backward compatibility check if the file exists on the remote; it should take precedence
if not self._remote_file_exists(source):
try:
source = self._loader.get_real_file(self._find_needle('files', source))
new_module_args['src'] = source
except AnsibleFileNotFound as e:
# module handles error message for nonexistent files
new_module_args['src'] = source
except AnsibleError as e:
raise AnsibleActionFail(to_text(e))

# execute the aws_s3 module now, with the updated args
result.update(self._execute_module(module_args=new_module_args, task_vars=task_vars))
Expand Down

0 comments on commit 8127e77

Please sign in to comment.