How to log anisble execution output to a single log file ?

I am trying to store the tasks execution results into a single file . In shell scripting, I could just use  >>logfile.log etc to send the commands execution and keep appending the file, but I did not see anything as such in ansible.. 
Any ideas ? 
  • post-author-pic
    James M

    Hi Surya,

    If you simply want to capture your ansible output then shell redirection will work.  Use the -v option if you want verbose logging and make sure to redirect stderr as well.   Something like this would work.

    ansible-playbook -v your_playbook.yml 2>&1 >> some.log 

    To make sure that you can see the output in your terminal as well, use tee.

    ansible-playbook -v your_playbook.yml 2>&1 | tee -a some.log

    You can also configure ansible to log to a file.

    ...via ansible.cfg


    ... via environment variables

    export ANSIBLE_LOG_PATH="/var/log/your_log_file_name"


  • post-author-pic
    Surya M

    Thank you . 

    I will take some time to rewrite my playbook to include this 
    Thank you so much 

Looking For Team Training?

Learn More