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

后端 未结 4 1716
渐次进展
渐次进展 2021-01-30 16:41

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

4条回答
  •  故里飘歌
    2021-01-30 16:56

    There's a couple of things you can do, but as you have rightly pointed out, Ansible in its current form doesn't really offer a good solution.

    Official-ish solutions:

    One idea is to mark the task as async and poll it. Obviously this is only suitable if it is capable of running in such a manner without causing failure elsewhere in your playbook. The async docs are here and here's an example lifted from them:

    - hosts: all
      remote_user: root
      tasks:
      - name: simulate long running op (15 sec), wait for up to 45 sec, poll every 5 sec
        command: /bin/sleep 15
        async: 45
        poll: 5
    

    This can at least give you a 'ping' to know that the task isn't hanging.

    The only other officially endorsed method would be Ansible Tower, which has progress bars for tasks but isn't free.

    Hacky-ish solutions:

    Beyond the above, you're pretty much going to have to roll your own. Your specific example of synching an S3 bucket could be monitored fairly easily with a script periodically calling the AWS CLI and counting the number of items in a bucket, but that's hardly a good, generic solution.

    The only thing I could imagine being somewhat effective would be watching the incoming ssh session from one of your nodes.

    To do that you could configure the ansible user on that machine to connect via screen and actively watch it. Alternatively perhaps using the log_output option in the sudoers entry for that user, allowing you to tail the file. Details of log_output can be found on the sudoers man page

提交回复
热议问题