Category: Linux

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

SaltStack Essential Reading

A list of ‘Essential Reading’ for SaltStack. A collection of useful links, mostly for myself but possibly helpful to others.

Next Page »