I have a cron job that runs a playbook quarterly. For this one playbook only I wish to log to a separate file (for audit reasons). Is this possible with a command line switch? I haven’t seen a way to do this online, nor do I see any options–hence the reason I am asking. I don’t care if it continues to copy it to ansible.log, I just need the output for this one run in another file.
I am currently getting the information right now with a sed command, but am curious if there is another way via ansible to pipe the output for this one play to another log:
`
crontab command:
echo “=fetch_start=” >> /var/log/ansible.log; ansible-playbook /some/path/main.yml -f 1 -e host=production; echo “=fetch_stop=” >> /var/log/ansible.log
sed:
sed -n ‘/=fetch_start=/,/=fetch_stop=/p’ /var/log/ansible.log > /var/log/fetch_users-ansible.log
`
Just set the environment variable ANSIBLE_LOG_PATH
https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-log-path
Thanks again Kai
I set this on the play level; however, it fails to create the file. Am I missing something?
`
You would need to set it before you start ansible-playbook, you can do this in your crontab
ANSIBLE_LOG_PATH=/tmp/fetch_admin_users_ansible.log ansible-playbook ....
ok, thank you.