This is a text-only version of the following page on https://raymii.org:
---
Title       :   log_vcs - Ansible callback plugin that creates VCS (git) branches for every Ansible run
Author      :   Remy van Elst
Date        :   10-07-2018
URL         :   https://raymii.org/s/software/log_vcs_-_Ansible_Callback_plugin_that_creates_git_branches_for_every_ansible_run.html
Format      :   Markdown/HTML
---



This callback plugin creates a VCS branch every time you run Ansible. If you
ever need to go back to a certain state or environment, check out that branch
and be sure nothing has changed.

This is useful when you have multiple environments or multiple people deploying
and continually develop your Ansible. When you often deploy to test / acceptance
and less often to production, you can checkout the last branch that deployed to
production if a hotfix or other maintenance is required, without having to
search back in your commits and logs. I would recommend to develop
infrastructure features in feature branches and have the master branch always
deployable to production. However, reality learns that that is not always the
case and this is a nice automatic way to have a fallback.

<p class="ad"> <b>Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below:</b><br><br> <a href="https://leafnode.nl">I'm developing an open source monitoring app called  Leaf Node Monitoring, for windows, linux & android. Go check it out!</a><br><br> <a href="https://github.com/sponsors/RaymiiOrg/">Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.</a><br><br> <a href="https://www.digitalocean.com/?refcode=7435ae6b8212">You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $100 credit for 60 days. </a><br><br> </p>


## Requirements and installation

The plugin requires 'GitPython'. On Ubuntu this can be installed with the
package manager:



   apt-get install python-git python3-git


The plugin requires the Ansible folder to be a git repository. If you have a
seperate 'roles' directory, that is not included in this plugin.

The plugin is hosted on [Github: https://github.com/RaymiiOrg/log_vcs][2]

To install the plugin, create a folder in your Ansible folder:



   mkdir -p plugins/callbacks


Place the file in there and edit your `ansible.cfg` file:



     [defaults]
     callback_whitelist = log_vcs
     callback_plugins = plugins/callbacks


## Environments

If you have multiple environments (multiple inventories) then every inventory
needs a `group_var` (in `group_vars/all.yml`) named `environment`. The plugin
uses this in the branch name. In my case it can be `dev`, `tst`, `acc`, `prd` or
`mgmt`. It is not required, if it is not found the plugin will substitute it
with `env`.

## Branch name format

The branch name format is:



   auto-$year$month$dayT$hour$minute-$env-$branch-$username-$playbook-filename


For example:



   auto-20180710T100719-env-master-remy-nginx-vps-for-raymii.org.yml


or:



     auto-20180709T161235-tst-refactor-for-odoo-remy-odoo.yml
     auto-20180710T091419-prd-refactor-for-odoo-remy-ping.yml


## Auto-commit or cleanup?

There is no auto-commit or auto-push to a git server. In my use-case deployment
is always done from a management machine, otherwise you have to extend the
plugin to do auto-commit and push. I decided in my case it would not be useful.

Auto-cleanup is also not implemented. We have bash for that:



   git branch | grep 'auto-' | xargs -L 1 -I % git branch -d %


  [1]: https://www.digitalocean.com/?refcode=7435ae6b8212
  [2]: https://github.com/RaymiiOrg/log_vcs

---

License:
All the text on this website is free as in freedom unless stated otherwise.
This means you can use it in any way you want, you can copy it, change it
the way you like and republish it, as long as you release the (modified)
content under the same license to give others the same freedoms you've got
and place my name and a link to this site with the article as source.

This site uses Google Analytics for statistics and Google Adwords for
advertisements. You are tracked and Google knows everything about you.
Use an adblocker like ublock-origin if you don't want it.

All the code on this website is licensed under the GNU GPL v3 license
unless already licensed under a license which does not allows this form
of licensing or if another license is stated on that page / in that software:

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

Just to be clear, the information on this website is for meant for educational
purposes and you use it at your own risk. I do not take responsibility if you
screw something up. Use common sense, do not 'rm -rf /' as root for example.
If you have any questions then do not hesitate to contact me.

See https://raymii.org/s/static/About.html for details.