# separate logfile per target

**URL:** <https://forum.ansible.com/t/separate-logfile-per-target/38175>\
**Category:** Ansible Project\
**Created:** [June 30, 2023, 6:54am UTC](https://forum.ansible.com/t/separate-logfile-per-target/38175 "2023-06-30T06:54:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [June 30, 2023, 6:54am UTC](https://forum.ansible.com/t/separate-logfile-per-target/38175/1 "2023-06-30T06:54:13Z")

</div>

we where wondering whether there is a method to generate logfiles per remote target on playbook executions?

In other words … one runs a playbook on 50 targets and gets 50 logfiles (1 per target) out of it.

I guess another way to separate things a litte in the logs would be to use serial: 1

---

<div class="post-metadata">

**Author:** ![Thanh\_Nguyen\_Duc](https://avatars.discourse-cdn.com/v4/letter/t/c89c15/32.png) [@Thanh\_Nguyen\_Duc](https://forum.ansible.com/u/Thanh_Nguyen_Duc)\
**Post date:** [June 30, 2023, 7:19am UTC](https://forum.ansible.com/t/separate-logfile-per-target/38175/2 "2023-06-30T07:19:02Z")

</div>

You may create a log file with hostname, in my case i will create a log file with name: {{inventory\_hostname}}\_log.xx then pull them back.

Vào Th 6, 30 thg 6, 2023 vào lúc 14:54 dulhaver via Ansible Project \<[ansible-project@googlegroups.com](mailto:ansible-project@googlegroups.com)\> đã viết:

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [June 30, 2023, 10:52am UTC](https://forum.ansible.com/t/separate-logfile-per-target/38175/3 "2023-06-30T10:52:42Z")

</div>

hi,

> You may create a log file with hostname, in my case i will create a log file with name: {{inventory\_hostname}}\_log.xx then pull them back.

that’s what I want. Good to hear that you are doing that. Can you share how that practically is being achieved?

putting …

log\_path = {{ inventory\_hostname }}\_ansible.log

… in the ansible.cfg does not work

---

<div class="post-metadata">

**Author:** ![Thanh\_Nguyen\_Duc](https://avatars.discourse-cdn.com/v4/letter/t/c89c15/32.png) [@Thanh\_Nguyen\_Duc](https://forum.ansible.com/u/Thanh_Nguyen_Duc)\
**Post date:** [June 30, 2023, 11:20am UTC](https://forum.ansible.com/t/separate-logfile-per-target/38175/4 "2023-06-30T11:20:18Z")

</div>

You want log for client or ansible system log? In my case i use j2 template to create a log with csv format to monitor certain tasks to check the timing of the main tasks if be executed and how long it took. Not sure this is what you want? If you want the log which record all stdout of everything for each playbook per each managed host then you may try the below

 ![image0.png](https://us1.discourse-cdn.com/ansible/original/2X/7/7f1051fa2f9ea3abab67284ba896046022517916.png)

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [June 30, 2023, 3:29pm UTC](https://forum.ansible.com/t/separate-logfile-per-target/38175/5 "2023-06-30T15:29:05Z")

</div>

Maybe I am not explaining myself good enough

- I run a playbook against 30 targets

- By default I get the complete log (TASKS by TASK) inside an ansible.log file (so all targets mixed into one big logfile)

- I want to receive 30 (1 logfile per target) logfiles instead

> **(attachments)**
>
> ![image0.png](https://us1.discourse-cdn.com/ansible/original/2X/7/7f1051fa2f9ea3abab67284ba896046022517916.png)

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [June 30, 2023, 4:14pm UTC](https://forum.ansible.com/t/separate-logfile-per-target/38175/6 "2023-06-30T16:14:10Z")

</div>

Please check the tree callback plugins - [https://docs.ansible.com/ansible/latest/collections/ansible/builtin/tree\_callback.html](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/tree_callback.html)  
This callback plugin logs on per-host basis.

```auto
[defaults]
stdout_callback=tree
inventory=hosts

[callback_tree]
directory=<LOG_DIRECTORY>/tree

```

will generate -

```auto

# ls -l tree
total 16
-rw-r--r-- 1 akasurde staff 40 30 Jun 09:10 192.168.64.3
-rw-r--r-- 1 akasurde staff 40 30 Jun 09:10 localhost

```

> **(attachments)**
>
> ![image0.png](https://us1.discourse-cdn.com/ansible/original/2X/7/7f1051fa2f9ea3abab67284ba896046022517916.png)

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [July 2, 2023, 3:05pm UTC](https://forum.ansible.com/t/separate-logfile-per-target/38175/7 "2023-07-02T15:05:36Z")

</div>

thx, that’s what I was looking for.
