ansibleansible-2.x

ansible copy module to set max execution time and fail task if it crosses time


- name: Copy generic files asynchronously with retries
  ansible.builtin.copy:
      src: "{{ item.src }}"
      dest: "{{ item.dest }}"
  with_items:
    - { src: 'files/scripts/ebslookup.sh', dest: '/tmp' }
    - { src: 'files/scripts/findmount.py', dest: '/tmp' }
    - { src: 'files/scripts/partedebslookup.py', dest: '/tmp' }
  async: 120
  poll: 0
  register: copy_result

I am getting error mentioning async is not supported for this task. Is there a way to set max execution for copy module and fail the task if it reaches max time


Solution

  • - name: Copy generic files with retries
      ansible.builtin.copy:
          src: "{{ item.src }}"
          dest: "{{ item.dest }}"
      with_items:
        - { src: 'files/scripts/ebslookup.sh', dest: '/tmp/scripts/' }
        - { src: 'files/scripts/findmount.py', dest: '/tmp/scripts/' }
        - { src: 'files/scripts/partedebslookup.py', dest: '/tmp/scripts/' }
      timeout: 60
      register: prepare_ebs_result
    

    I am able to achieve max execution time with timeout. If it reaches max time then we will get below error: "msg": "The ansible.builtin.copy action failed to execute in the expected time frame (2) and was terminated"}