Bash script and yml file output

6,001

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?

Share:
6,001

Related videos on Youtube

nicoX
Author by

nicoX

Updated on September 18, 2022

Comments

  • nicoX
    nicoX over 1 year

    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.

    • FrustratedWithFormsDesigner
      FrustratedWithFormsDesigner about 9 years
      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...