Skip to content

Commit

Permalink
Track configuration in local git repositories
Browse files Browse the repository at this point in the history
Fixes #3162.
  • Loading branch information
djmitche committed Jan 19, 2015
1 parent be27bbb commit ebeb8d0
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
13 changes: 13 additions & 0 deletions group_vars/all
Expand Up @@ -95,3 +95,16 @@ slave_master_allocations:
- cm-bbot-xp-001
- cm-bbot-xp-002
- cm-bbot-xp-003

# configuration for tracking configuration directories
track_config:
# Directories to track. It's OK if these don't exist
# everywhere -- they will only be tracked if they exist.
dirs:
- "/etc"
- "/usr/local/etc"
- "/usr/local/mailman/configs"
author_name: "Ansible"
author_email: "sysadmin@buildbot.net"
default_author_name: "Unknown"
default_author_email: "sysadmin@buildbot.net"
8 changes: 8 additions & 0 deletions local.yml
Expand Up @@ -18,6 +18,10 @@
key: "{{ansible_hostname}}"
changed_when: False

- include: "track-config.yml"
vars:
commit_message: "pre-ansible checkin"

# Service hosts and their jails
- include: "host-service1.yml"
- include: "jail-ns1.yml"
Expand All @@ -40,4 +44,8 @@
- include: "jail-docs.yml"
- include: "jail-www.yml"

- include: "track-config.yml"
vars:
commit_message: "post-ansible checkin"

# vim:ts=2:sw=2:noai:nosi
32 changes: 32 additions & 0 deletions templates/track-config.sh
@@ -0,0 +1,32 @@
#! /bin/sh

set -e

dir="${1}"
commit_message="${2}"

if ! [ -d "${dir}" ]; then
# nothing to track
exit 0
fi
cd "${dir}"

if ! [ -d ".git" ]; then
git init
fi

# unconditionally update the config as necessary
git config user.email "{{ track_config['default_author_email'] }}"
git config user.name "{{ track_config['default_author_name'] }}"

# check for changes
if git status 2>/dev/null | grep -q 'working directory clean'; then
exit 0
fi

# use git add --all to capture deletes, too
git add --all .

# commit the changes
git commit --author='{{ track_config['author_name'] }} <{{ track_config['author_email'] }}>' \
-m "${commit_message}"
18 changes: 18 additions & 0 deletions track-config.yml
@@ -0,0 +1,18 @@
---
# see #3162 for the background of this technique
- name: track configuration locally
hosts: all
gather_facts: no
connection: local
sudo: yes
tasks:
- name: install track-config.sh
template:
src: "templates/track-config.sh"
dest: "/root/track-config.sh"
mode: 0755

- name: track configuration
command: "/root/track-config.sh {{ item }} '{{ commit_message }}'"
with_items: track_config['dirs']
changed_when: False

0 comments on commit ebeb8d0

Please sign in to comment.