ansibleansible-2.x

How can I show progress for a long-running Ansible task?


I have a some Ansible tasks that perform unfortunately long operations - things like running an synchronization operation with an S3 folder. It's not always clear if they're progressing, or just stuck (or the ssh connection has died), so it would be nice to have some sort of progress output displayed. If the command's stdout/stderr was directly displayed, I'd see that, but Ansible captures the output.

Piping output back is a difficult problem for Ansible to solve in its current form. But are there any Ansible tricks I can use to provide some sort of indication that things are still moving?

Current ticket is https://github.com/ansible/ansible/issues/4870


Solution

  • Ansible has since implemented the following:

    ---
    # Requires ansible 1.8+
    - name: 'YUM - async task'
      yum:
        name: docker-io
        state: installed
      async: 1000
      poll: 0
      register: yum_sleeper
    
    - name: 'YUM - check on async task'
      async_status:
        jid: "{{ yum_sleeper.ansible_job_id }}"
      register: job_result
      until: job_result.finished
      retries: 30
    

    For further information, see the official documentation on the topic (make sure you're selecting your version of Ansible).