Rancid and Git

One of the thing that was a mild irritation was that Rancid didn’t work with git.

Mostly it didn’t matter, because there were easy enough ways to run rancid with a different version control system. Along comes Rancid 3.2 and it has git support. Great, now we can migrate rancid and only maintain a single VCS.

Using Rancid and Git

Worth noting, this doesn’t cover the bulk of what is required for setting up Rancid. It only details the aspects that intersect with using Git. If you want more details on setting up Rancid, see my previous writeup . It also doesn’t cover the conversion from CVS to Git or SVN to Git .

The rancid config file is in /usr/local/etc/rancid/. Stripping out all the comments in rancid.conf, it looks like this (after I’ve modified it):

 1TERM=network;export TERM
 2LC_COLLATE="POSIX"; export LC_COLLATE
 3uid=`/usr/local/bin/perl -e 'print "$>"'`
 4test "$uid" -eq 0 && echo "Do not run $0 as root!" && exit 1
 5umask 027
 6PERL5LIB="/usr/local/lib/rancid"; export PERL5LIB
 7TMPDIR=/tmp; export TMPDIR
 8BASEDIR=/var/rancid; export BASEDIR
 9PATH=/usr/local/libexec/rancid:/usr/local/bin:/usr/sbin:/usr/bin:/bin; export PATH
10SENDMAIL="/usr/sbin/sendmail"
11CVSROOT=$BASEDIR/CVS; export CVSROOT
12LOGDIR=$BASEDIR/logs; export LOGDIR
13RCSSYS=git; export RCSSYS
14ACLFILTERSEQ=NO; export FILTERSEQ
15NOPIPE=NO; export NOPIPE
16FILTER_PWDS=YES; export FILTER_PWDS
17NOCOMMSTR=YES; export NOCOMMSTR
18FILTER_OSC=YES; export FILTER_OSC
19MAX_ROUNDS=4; export MAX_ROUNDS
20OLDTIME=4; export OLDTIME
21LOCKTIME=4; export LOCKTIME
22PAR_COUNT=5; export PAR_COUNT
23LIST_OF_GROUPS="cmhome"
24MAILDOMAIN="@cmhome"; export MAILDOMAIN
25MAILHEADERS="Precedence: bulk\nAuto-submitted: auto-generated\nX-Auto-Response-Suppress: All"; export MAILHEADERS

The important part here is that you’ve specified ‘git’ as the value for RCSSYS.

Now we need to clone our repo

1git clone <remote git server>/path/to/rancid_repo.git

If your repo isn’t the same name as your group, that’s fine. Just symlink it. For example

1ln -s switch-configs cmhome

My repo has the following items in it:

  • cmhome: directory where configs are stored
  • crontab: rancid’s crontab

The crontab has 2 entries in it, 1 to run rancid, and the other to clean up the logs directory periodically.

1SHELL=/usr/local/bin/bash
2PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
3#MAILTO=
4HOME=/var/rancid
5# Cleanup log files hourly
61	*	*	*	*	/usr/bin/find /var/rancid/logs/ -type f -cmin +120 -delete
7
8# do a rancid-run every */30min
9*/30	*	*	*	*	/usr/local/bin/rancid-run > /dev/null

We want to edit the commit hook so it does an automatic push. That way we can always see our current status when we look at the Git server.

Add or append the following to the rancid_repo/.git/hooks/post-commit

1#!/bin/sh
2# push the local repo to the remote server on commit
3git push origin

By default, rancid-run will execute from ~rancid. If your repo contains your config directory (like mine), you can create a symlink to it. Mine looks like this:

1[louisk@rancid louisk 21 ]$ ls -l ~rancid/
2lrwxr-xr-x  1 rancid  rancid    13B Nov 12 22:42 cmhome@ -> rancid/cmhome
3drwxr-x---  2 rancid  rancid     6B Nov 12 23:15 logs/
4drwxr-xr-x  4 rancid  rancid     8B Nov 12 23:27 rancid/
5[louisk@rancid louisk 22 ]$

You should now be able to execute rancid-run and have it store your config bits in Git.

Web Interface

There are lots of ways to get a git repo viewable from a web interface. I’m currently using Gogs . There is little to setup, and not many dependancies.

NOTE at some point, the routers.db file changed from using ‘:’ to ‘;’. If you get errors about the FS (field seperator), you probably need to change this.


Footnotes and References

Copyright

Comments