Score:0

Ansible playbook with 'async' outputs out of order when executing on multiple servers

gb flag

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.

U880D avatar
ca flag
Can you provide more information regarding the script? What it the content of, what it is doing, what do you try achieve with it?
Score:-1
gb flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.