# custom logging for one role

**URL:** <https://forum.ansible.com/t/custom-logging-for-one-role/27942>\
**Category:** Ansible Project\
**Created:** [July 3, 2018, 9:05pm UTC](https://forum.ansible.com/t/custom-logging-for-one-role/27942 "2018-07-03T21:05:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [July 3, 2018, 9:05pm UTC](https://forum.ansible.com/t/custom-logging-for-one-role/27942/1 "2018-07-03T21:05:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [July 3, 2018, 9:31pm UTC](https://forum.ansible.com/t/custom-logging-for-one-role/27942/2 "2018-07-03T21:31:10Z")

</div>

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

`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 3, 2018, 10:50pm UTC](https://forum.ansible.com/t/custom-logging-for-one-role/27942/3 "2018-07-03T22:50:42Z")

</div>

Just set the environment variable ANSIBLE\_LOG\_PATH  
[https://docs.ansible.com/ansible/latest/reference\_appendices/config.html#default-log-path](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-log-path)

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [July 5, 2018, 4:31pm UTC](https://forum.ansible.com/t/custom-logging-for-one-role/27942/4 "2018-07-05T16:31:17Z")

</div>

Thanks again Kai

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [July 5, 2018, 7:05pm UTC](https://forum.ansible.com/t/custom-logging-for-one-role/27942/5 "2018-07-05T19:05:19Z")

</div>

I set this on the play level; however, it fails to create the file. Am I missing something?

`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 5, 2018, 7:20pm UTC](https://forum.ansible.com/t/custom-logging-for-one-role/27942/6 "2018-07-05T19:20:23Z")

</div>

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 ....

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [July 5, 2018, 7:23pm UTC](https://forum.ansible.com/t/custom-logging-for-one-role/27942/7 "2018-07-05T19:23:55Z")

</div>

ok, thank you.
