How Do I Log Task Output To A File?

HOW TO -️ October 18, 2021

One of my ansible tasks imports an Oracle database using impdp.

This generates a lot of output to the console so I have set no_log: True.

However, when this fails I want to see the log!

How can I make this particular task log to a file and not to the console?


You're using the command module? One idea [more of a hack] would be to write the logs to some external file, and then having a task after it which makes use of failed\_when condition, and remove the log file, if the prev. task was succesful :) Why can you see the console output during successful runs anyway? I've not seen a configuration for, nor did I think it was possible to, show stdout during a successful task execution, it should just come up [ ok: host name ]. However when an error is detected the output gets dumped to the ansible control console (and any ansible logs defined) would you mind sharing the configuration which gives you the large stdout during a regular successful run? @hvindin Put in -vvv after the ansible-playbook command for getting verbose logs. Have you considered using less v's? Each one makes it all the more verbose. Or perhaps running without verbose mode on at all, if a step fails ansible should print the entire stout/stderr/rc/etc. That causes the failure without any verbose logging. @hvindin Have expanded my comment to an answer. Does that help? Registering a variable does seem the best logical move, see my comment on your answer for my opinions about what to do with the outputs from ansible triggered commands.