# Adding --tree to ansible-playbook

**URL:** <https://forum.ansible.com/t/adding-tree-to-ansible-playbook/11802>\
**Category:** Ansible Project\
**Created:** [August 16, 2012, 3:49pm UTC](https://forum.ansible.com/t/adding-tree-to-ansible-playbook/11802 "2012-08-16T15:49:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [August 16, 2012, 3:49pm UTC](https://forum.ansible.com/t/adding-tree-to-ansible-playbook/11802/1 "2012-08-16T15:49:53Z")

</div>

Michael: could you elaborate on the TO DO in this block of code from  
ansible.utils:

def write\_tree\_file(tree, hostname, buf):  
&nbsp;&nbsp;&nbsp;&nbsp;''' write something into treedir/hostname '''

&nbsp;&nbsp;&nbsp;&nbsp;# TODO: might be nice to append playbook runs per host in a similar way  
&nbsp;&nbsp;&nbsp;&nbsp;# in which case, we'd want append mode.  
&nbsp;&nbsp;&nbsp;&nbsp;path = os.path.join(tree, hostname)  
&nbsp;&nbsp;&nbsp;&nbsp;fd = open(path, "w+")  
&nbsp;&nbsp;&nbsp;&nbsp;fd.write(buf)  
&nbsp;&nbsp;&nbsp;&nbsp;fd.close()

Where you thinking of simply appending the results from each host or  
something more? Any changes to the data structure? Which task wrote  
them? Any timestamps?

I ask because I could use something that dumps the results of a  
playbook run so I can compile a report about our hosts. Most of the  
information I need is in the setup facts and a bit more of it I can  
collect with a custom module returning its own facts. I was trying to  
figure out something using a module that used a local connection, but  
in digging through the code came across the --tree option in  
bin/ansible and the code and comments in ansible.utils.

I can give implementing something for playbooks a good, but could use  
a bit more feedback so I don't develop something too off the mark.

Thanks.

\<tim/\>

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 16, 2012, 5:48pm UTC](https://forum.ansible.com/t/adding-tree-to-ansible-playbook/11802/2 "2012-08-16T17:48:51Z")

</div>

I'm not going to make tree work this way anymore, but I am considering  
making a configurable path in the config file, where we could have a  
per-host log for what happens to individual hosts.

Basically think /var/log/ansible/hosts/$hostname.log

And you would see both the operations executed and the returns for  
each host. I'd probably intend to make this generally parseable  
with each log entry remaining JSON.

(I don't think this requires modular callbacks as it's something I  
would want to include in core. It would not require any special CLI  
flags)

(There's also syslog logging on the remote hosts already)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 16, 2012, 5:51pm UTC](https://forum.ansible.com/t/adding-tree-to-ansible-playbook/11802/3 "2012-08-16T17:51:25Z")

</div>

BTW, modular callbacks I haven't talked about, but I alluded a bit  
earlier to being able to save things in different datastores.

Everyone should read here:

[https://github.com/ansible/ansible/issues/862](https://github.com/ansible/ansible/issues/862)

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [August 16, 2012, 8:04pm UTC](https://forum.ansible.com/t/adding-tree-to-ansible-playbook/11802/4 "2012-08-16T20:04:19Z")

</div>

OK. Sounds good.

In the meanwhile I have to compile information about each of our  
hosts. Is there anything I can do short of writing some one off  
scripts using the API? You cannot pass a whole data structure in to a  
playbook task action that could write a file or a row.

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 16, 2012, 8:09pm UTC](https://forum.ansible.com/t/adding-tree-to-ansible-playbook/11802/5 "2012-08-16T20:09:32Z")

</div>

I suggest an API script using something like your own version of the  
setup module (call it site\_facts), or just use tree with it.

If that doesn't work, then no, you have nothing in terms of a  
machine-readable host history yet.
