Category: Linux

Devops and Old Git Branches

A guest blog post I wrote on managing git branches when doing devops.

When doing Devops we all know that using source code control is a “good thing” — indeed it would be hard to imagine doing Devops without it. But if you’re using Puppet and R10K for your configuration management you can end up having hundreds of old branches lying around — branches like XYZ-123, XYZ-123.fixed, XYZ-123.fixed.old and so on. Which branches to cleanup, which to keep? How to easily cleanup the old branches? This article demonstrates some git configurations and scripts  that make working with hundreds of git branches easier…

Go to Devops and Old Git Branches to read the full article.

SaltStack Ubuntu Hostname

SaltStack currently doesn’t set the hostname correctly on Debian/Ubuntu. For example, this won’t work:

      - enabled: True
      - hostname:

Here’s a little shell script I wrote, to get around this problem:

% cat 

hostname $hn
echo $hn > /etc/hostname
sed -i "1s/.*/ localhost $hn/" /etc/hosts

Then apply it using cmd.script, for example:

    - source: salt://soe/
    - args:
    - unless: grep -q "" /etc/hosts

Terraform Presentation

Here are the slides from my Terrraform presentation at the Sydney Puppet Meetup.

Building the development version of Terraform

Instructions on how to build the development version of Terraform.

First you need to install Go, I have a script for this that would be easy to adapt for your needs. It installs Go, but also downloads some common projects (go-bindata, lint) and my own projects (gosnmp, evaler).


## install go


if ! [ -f /var/tmp/$tgz ] ; then
	cd /var/tmp
	wget $url

if ! [ -d /usr/local/go ] ; then
	sudo tar -C /usr/local -xzf /var/tmp/$tgz

## setup dev directory structure

mkdir -p ~/go/{sonia,thirdparty}/{bin,pkg,src}

cd ~/go/thirdparty/src

read -p "Install third party repos? (go-bindata, lint)"
if [[ $REPLY =~ ^[Yy]$ ]] ; then
	if ! [ -d ] ; then
		go get
		cp ~/go/thirdparty/bin/go-bindata ~/bin

	if ! [ -d ] ; then
		go get
		cp ~/go/thirdparty/bin/golint ~/bin

cd ~/go/sonia/src

read -p "Install soniah repos? (gosnmp, evaler)"
if [[ $REPLY =~ ^[Yy]$ ]] ; then
	# do 'git clone' not 'go get' so origin is writeable
	if ! [ -d $dir/evaler ] ; then
		mkdir -p $dir
		cd $dir
		git clone
		cd -
	if ! [ -d $dir/gosnmp ] ; then
		mkdir -p $dir
		cd $dir
		git clone
		cd -

A common pattern in Go (which my setup script demonstrates) is to split your code from thirdparty code. This requires configuring your shell (~/.zshrc, ~/.bashrc):

export GOPATH=~/go/thirdparty:~/go/sonia                                          
export PATH=${GOPATH//://bin:}/bin:$PATH

Then you need to follow the Terraform instructions for building, that is:

$ cd ~/go/thirdparty/src
$ go get -u
$ cd ~/go/thirdparty/src/
$ make updatedeps
$ make dev
# put the binaries somewhere in your path, eg /usr/local/bin
$ sudo cp bin/terraform* /usr/local/bin

Git and mercurial abort: revision cannot be pushed

I’ve been migrating some repositories from Mercurial to Git; as part of this migration process some users want to keep using Mercurial locally until they have time to learn git.

First install the hg-git tools; for example on Ubuntu:

sudo aptitude install python-setuptools python-dev
sudo easy_install hg-git

Make sure the following is in your ~/.hgrc:

hgext.bookmarks =
hggit = 

Then, in your existing mercurial repository, add a new remote that points to the git repository. For example for a BitBucket repository:

cd <mercurial repository>
cat .hg/hgrc
# the original hg repository
default =
# the git version (on BitBucket in this case)
bbgit   = git+ssh://

Then you can go an hg push bbgit to push from your local hg repository to the remote git repository.

mercurial abort: revision cannot be pushed

You may get the error mercurial abort: revision cannot be pushed since it doesn’t have a ref when pushing from hg to git, or you might notice that your hg work isn’t being pushed. The solution here is to reset the hg bookmark for git’s master branch:

hg book -f -r tip master
hg push bbgit

If you find yourself doing this regularly, this small shell function (in your ~/.bashrc) will help:

hggitpush () {
   # $1 is hg remote name in hgrc for repo
   # $2 is branch (defaults to master)
   hg book -f -r tip ${2:-master}
   hg push $1

Then from your shell you can run commands like:

hggitpush bbgit dev
hggitpush foogit      # defaults to pushing to master
Next Page »