From fe2520a8308d84bb4c5d3e06a05bbd3ab60f2e74 Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Thu, 7 Jun 2018 20:12:13 -0400 Subject: [PATCH] 2.5 backport #40826 to fix async for aws_s3 (#41276) * cherry-picked from 89cea78e3002c816157e604c73e7eb4db137b107 and fixed merge conflicts from restructuring the integration tests in devel Fix async for aws_s3 Add a test that async is able to be used on aws_s3 tasks (cherry picked from commit cef92e3942cdd76866c47d25f903625e6d7eb6ed) * changelog format tweak --- changelogs/fragments/aws_s3_async_fix.yaml | 3 +++ lib/ansible/plugins/action/aws_s3.py | 13 +++++++++++-- test/integration/targets/aws_s3/tasks/main.yml | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/aws_s3_async_fix.yaml diff --git a/changelogs/fragments/aws_s3_async_fix.yaml b/changelogs/fragments/aws_s3_async_fix.yaml new file mode 100644 index 00000000000..ae049267173 --- /dev/null +++ b/changelogs/fragments/aws_s3_async_fix.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- aws_s3 - add async support to the action plugin (https://github.com/ansible/ansible/pull/40826) diff --git a/lib/ansible/plugins/action/aws_s3.py b/lib/ansible/plugins/action/aws_s3.py index a2ee822ad39..a454922a101 100644 --- a/lib/ansible/plugins/action/aws_s3.py +++ b/lib/ansible/plugins/action/aws_s3.py @@ -23,6 +23,7 @@ import os from ansible.errors import AnsibleError, AnsibleAction, AnsibleActionFail, AnsibleFileNotFound from ansible.module_utils._text import to_text from ansible.plugins.action import ActionBase +from ansible.utils.vars import merge_hash class ActionModule(ActionBase): @@ -31,6 +32,8 @@ class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None): ''' handler for aws_s3 operations ''' + self._supports_async = True + if task_vars is None: task_vars = dict() @@ -55,8 +58,14 @@ class ActionModule(ActionBase): 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)) + wrap_async = self._task.async_val and not self._connection.has_native_async + # execute the aws_s3 module with the updated args + result = merge_hash(result, self._execute_module(module_args=new_module_args, task_vars=task_vars, wrap_async=wrap_async)) + + if not wrap_async: + # remove a temporary path we created + self._remove_tmp_path(self._connection._shell.tmpdir) + except AnsibleAction as e: result.update(e.result) return result diff --git a/test/integration/targets/aws_s3/tasks/main.yml b/test/integration/targets/aws_s3/tasks/main.yml index 0b5562a3e52..5a19c952d75 100644 --- a/test/integration/targets/aws_s3/tasks/main.yml +++ b/test/integration/targets/aws_s3/tasks/main.yml @@ -65,6 +65,23 @@ - result.changed == True - result.msg == "PUT operation complete" # ============================================================ +- name: test using aws_s3 with async + aws_s3: + bucket: "{{ bucket_name }}" + mode: put + src: "{{ tmp1.path }}" + object: delete.txt + <<: *aws_connection_info + register: test_async + async: 30 + poll: 0 +- name: ensure it completed + async_status: + jid: "{{ test_async.ansible_job_id }}" + register: status + until: status.finished + retries: 10 +# ============================================================ - name: check that roles file lookups work as expected aws_s3: bucket: "{{ bucket_name }}"