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):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
TERM=network;export TERM LC_COLLATE="POSIX"; export LC_COLLATE uid=`/usr/local/bin/perl -e 'print "$>"'` test "$uid" -eq 0 && echo "Do not run $0 as root!" && exit 1 umask 027 PERL5LIB="/usr/local/lib/rancid"; export PERL5LIB TMPDIR=/tmp; export TMPDIR BASEDIR=/var/rancid; export BASEDIR PATH=/usr/local/libexec/rancid:/usr/local/bin:/usr/sbin:/usr/bin:/bin; export PATH SENDMAIL="/usr/sbin/sendmail" CVSROOT=$BASEDIR/CVS; export CVSROOT LOGDIR=$BASEDIR/logs; export LOGDIR RCSSYS=git; export RCSSYS ACLFILTERSEQ=NO; export FILTERSEQ NOPIPE=NO; export NOPIPE FILTER_PWDS=YES; export FILTER_PWDS NOCOMMSTR=YES; export NOCOMMSTR FILTER_OSC=YES; export FILTER_OSC MAX_ROUNDS=4; export MAX_ROUNDS OLDTIME=4; export OLDTIME LOCKTIME=4; export LOCKTIME PAR_COUNT=5; export PAR_COUNT LIST_OF_GROUPS="cmhome" MAILDOMAIN="@cmhome"; export MAILDOMAIN MAILHEADERS="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
git 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
ln -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.
1 2 3 4 5 6 7 8 9
SHELL=/usr/local/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin #MAILTO= HOME=/var/rancid # Cleanup log files hourly 1 * * * * /usr/bin/find /var/rancid/logs/ -type f -cmin +120 -delete # do a rancid-run every */30min */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 2 3
#!/bin/sh # push the local repo to the remote server on commit git 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 2 3 4 5
[louisk@rancid louisk 21 ]$ ls -l ~rancid/ lrwxr-xr-x 1 rancid rancid 13B Nov 12 22:42 cmhome@ -> rancid/cmhome drwxr-x--- 2 rancid rancid 6B Nov 12 23:15 logs/ drwxr-xr-x 4 rancid rancid 8B Nov 12 23:27 rancid/ [louisk@rancid louisk 22 ]$
You should now be able to execute rancid-run and have it store your config bits in Git.
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¶
So what do you think? Leave your comments below.