Category: Linux

SaltStack Ubuntu Hostname

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

system:
    network.system:
      - enabled: True
      - hostname: server1.example.com

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

% cat set_hostname.sh 
#!/bin/bash

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

Then apply it using cmd.script, for example:

foo-hostname:
  cmd.script:
    - source: salt://soe/set_hostname.sh
    - args: foo.bar.com
    - unless: grep -q "foo.bar.com" /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).

#!/bin/bash

## install go

tgz=go1.3.3.linux-amd64.tar.gz
url=https://storage.googleapis.com/golang/$tgz

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

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

## 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 github.com/jteeuwen/go-bindata ] ; then
		go get github.com/jteeuwen/go-bindata/...
		cp ~/go/thirdparty/bin/go-bindata ~/bin
	fi

	if ! [ -d github.com/golang/lint ] ; then
		go get github.com/golang/lint/golint
		cp ~/go/thirdparty/bin/golint ~/bin
	fi
fi

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
	dir=github.com/soniah
	if ! [ -d $dir/evaler ] ; then
		mkdir -p $dir
		cd $dir
		git clone git@github.com:soniah/evaler.git
		cd -
	fi

	dir=github.com/soniah
	if ! [ -d $dir/gosnmp ] ; then
		mkdir -p $dir
		cd $dir
		git clone git@github.com:soniah/gosnmp.git
		cd -
	fi
fi

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 github.com/mitchellh/gox
$ cd ~/go/thirdparty/src/github.com/hashicorp/terraform
$ 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:

[extensions]
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
[paths]
# the original hg repository
default = https://username@abcde.org/foo/barhg
# the git version (on BitBucket in this case)
bbgit   = git+ssh://git@bitbucket.org:foo/bar.git

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 »