# Best practice for recording Ansible provisioning runs

**URL:** <https://forum.ansible.com/t/best-practice-for-recording-ansible-provisioning-runs/15400>\
**Category:** Ansible Project\
**Created:** [June 4, 2014, 9:42am UTC](https://forum.ansible.com/t/best-practice-for-recording-ansible-provisioning-runs/15400 "2014-06-04T09:42:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Craig\_Marvelley](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@Craig\_Marvelley](https://forum.ansible.com/u/Craig_Marvelley)\
**Post date:** [June 4, 2014, 9:42am UTC](https://forum.ansible.com/t/best-practice-for-recording-ansible-provisioning-runs/15400/1 "2014-06-04T09:42:37Z")

</div>

Hi all,

I was wondering if anyone has a strategy for recording when a playbook has been run against hosts in an inventory, and crucially which version of the repository (Git-based, in my case) was checked out when the playbook ran? Essentially I’d like to maintain a ‘version number’ for each instance that indicates when they were last provisioned.

Cheers!  
Craig

---

<div class="post-metadata">

**Author:** ![Adam\_Morris](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@Adam\_Morris](https://forum.ansible.com/u/Adam_Morris)\
**Post date:** [June 4, 2014, 2:28pm UTC](https://forum.ansible.com/t/best-practice-for-recording-ansible-provisioning-runs/15400/2 "2014-06-04T14:28:47Z")

</div>

In a similar situation I simply added a play to the role that stores a version number as a local fact. Then on subsequent runs I can check that local fact. The only proviso for that is that it is possible for someone to change the fact so don't rely on it for anything truly important.

---

<div class="post-metadata">

**Author:** ![Adam\_Morris](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@Adam\_Morris](https://forum.ansible.com/u/Adam_Morris)\
**Post date:** [June 4, 2014, 8:19pm UTC](https://forum.ansible.com/t/best-practice-for-recording-ansible-provisioning-runs/15400/3 "2014-06-04T20:19:44Z")

</div>

Here’s how I set the fact…

# Create the local facts directory if it doesn’t exist

- name: ensure that the local facts directory exists  
file: state=directory path=“/etc/ansible/facts.d” mode=0755

# Set a local fact so that we don’t do this again

- name: update the widget facts file so that this is not run next time.  
ini\_file: dest=/etc/ansible/facts.d/widgets.fact section=installed  
option=version value={{ widgets\_latest\_version }} mode=0644

and in my case I add the following to all of the actual widget installation tasks so that I don’t reinstall (not quite your scenario)  
when: “widgets\_installed\_version != widgets\_latest\_version”

and in that role I have a defaults/main.yml which sets these…

widgets\_installed\_version: “{{ ansible\_local.widgets.installed.version | default(0) }}”

widgets\_latest\_version: “latest”

In your case you won’t need to check those local facts (unless you want to) but you can set as many facts as you want. The last modified time of the /etc/ansible/facts.d/widgets.fact file will tell you when it was last changed. If you rerun the playbook with the same version it will not update that time, if you store other facts you may also want to store times with them if they are all in the same facts file.

I hope that this helps,  
Adam

---

<div class="post-metadata">

**Author:** ![Paul\_Durivage](https://avatars.discourse-cdn.com/v4/letter/p/94ad74/32.png) [@Paul\_Durivage](https://forum.ansible.com/u/Paul_Durivage)\
**Post date:** [June 4, 2014, 9:20pm UTC](https://forum.ansible.com/t/best-practice-for-recording-ansible-provisioning-runs/15400/4 "2014-06-04T21:20:50Z")

</div>

Hi Craig,

I think what you’re looking for is callback plugins, but you could probably also use a notification module as well. There are several in Github as examples. The callback plugin could, for example, record something to a file, or to a database, or merely make an API call to some custom application that records the information you’re looking for.

[http://docs.ansible.com/developing\_plugins.html#callbacks](http://docs.ansible.com/developing_plugins.html#callbacks)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 6, 2014, 12:33pm UTC](https://forum.ansible.com/t/best-practice-for-recording-ansible-provisioning-runs/15400/5 "2014-06-06T12:33:09Z")

</div>

Ansible Tower contains some very nice logging of job history you may be interested in:

[http://www.ansible.com/tower](http://www.ansible.com/tower)

This is probably the easiest way to go because you don’t have to build it yourself, but there’s still a searchable REST API to access everything.

---

<div class="post-metadata">

**Author:** ![Craig\_Marvelley](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@Craig\_Marvelley](https://forum.ansible.com/u/Craig_Marvelley)\
**Post date:** [June 27, 2014, 8:02am UTC](https://forum.ansible.com/t/best-practice-for-recording-ansible-provisioning-runs/15400/6 "2014-06-27T08:02:05Z")

</div>

Thanks guys, think each of these are exactly what I need. I’ll give them a try. Thanks for the help!
