0

I have a playbook that is suppose to run a script on 5-10 servers in parallel

- name: Run script & cleanup
  ansible.builtin.shell: |
    ...
    bash {{ SCRIPT }}
    ...
  args:
    executable: /bin/bash
  async: 1800
  poll: 60

I have to add this async + poll because the script takes ~10 minutes to finish. If I don't specify them, Ansible complains that it lost connectivity to the server.

The script is executed in parallel on all servers so it finishes roughly at the same time on all of them. The script outputs 500-1000 lines of output. The problem is that the STDOUT that ansible outputs is all over the place. Ansible outputs:

  • some output from server 2
  • then some output from server 5
  • then some output from server 3
  • then again some more output from server 2
  • ...

It's a mess to read the logs and debug if there is an issue on some server.

How do I make ansible output the full output from the script for each server ?

This issue doesn't happen when I don't use "async", but as I said above, Ansible loses connection to the servers for some reason and I read that it's best practice to use "async" for long running tasks.

Subzero123
  • 49
  • 1
  • 6
  • Can you provide more information regarding the script? What it the content of, what it is doing, what do you try achieve with it? – U880D Aug 15 '23 at 14:58

1 Answers1

-1

I fixed the issue by:

  • Sending the script output to a log file
  • Using a post_tasks: play with throttle: 1 to cat <log_file>

There are probably other ways to do it, but this works.

Subzero123
  • 49
  • 1
  • 6