2

I'm trying to catch the stdout of a script to a file, and at the same time have it display its ongoing summary:

./RUN host-names ANSIBLE.yml 2>&1 | tee out.txt

What this does is that it displays and forwards the initial lines to out.txt, but from there on as it starts the actual host check, it stops displaying and forwarding to out.txt:

PLAY [all]
********************************************************************

GATHERING FACTS
********************************************************************

After the PLAY and GATHERING FACTS it continues with its work, but only if I run the script without the tee command:

ok: [host.com]
ok: [host.com]
ok: [host.com]
fatal: [host.com]

I would also be interested to only grep some of the output to the out.txt file, as fatal and leave out the ok hosts.

  • I've had a similar problem: I have a bash script which calls ansbible right at the end. The first part of the script displays on stdout immediately, but the ansible output doesn't appear until after ansible has completed. I'm guessing that ansible might not write directly to stdout where tee can capture it from, but I'm not sure... – FrustratedWithFormsDesigner Feb 23 '15 at 20:23
2

I found this page (https://coderwall.com/p/d5zqla/unbuffered-output-with-ansible-in-jenkins) that shows how to force output to be unbuffered.

I modified my script to look like this:

    export PYTHONUNBUFFERED=1
    ansible-playbook -i inventory site.yml

and I now get ansible output as the script runs. Does that help?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.