Skip to content

Instantly share code, notes, and snippets.

@bleach
Last active June 2, 2016 12:57
Show Gist options
  • Save bleach/3403299 to your computer and use it in GitHub Desktop.
Save bleach/3403299 to your computer and use it in GitHub Desktop.
How I manage my dot files

Here's how I solve the age old problem of getting my configuration files onto multiple machines.

I have a private git repo containing puppet manifests. I keep it separate from any other puppet configuration for two reasons:

  • I want to use it on personal machines without copying work data around to other machines
  • I don't want to worry about my personal puppet stuff breaking puppet runs

Here's an example node definition for my development VMs at songkick:

node /^of1-dev-graham(-lucid)?$/ {

  case $id {
    "root": {
      include graham::headless
    }
    "graham": {
      include graham_personal
    }
  }

}

If I'm running puppet as me, I configure my dot files, if I'm running as root I install some packages.

Within the graham_personal module I have this:

  file {"$graham_personal::homedir/.vimrc":
    source => "puppet:///graham_personal/home/graham/.vimrc",
    ensure => present,
  }

  file {"${graham_personal::homedir}/.vim":
    source  => "puppet:///graham_personal/home/graham/.vim",
    ensure  => directory,
    recurse => true,
  }

The $graham_personal::homedir is a variable that contains the path of my home directory (it's different on home machines, work machines and other machines that I have shell access to).

Note, the recurse => true on the second file resource. This means that I can put any file under modules/files/home/graham/.vim/ and it'll be installed.

I have a bin/puppet-run that looks like this:

#!/bin/bash

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

puppetdir=$(dirname $(dirname $0) | sed -e "s:^\.:$(pwd):")

puppet apply --modulepath=${puppetdir}/modules \
       --verbose ${puppetdir}/manifests/init.pp

When I'm using a new machine, I do this:

$ sudo apt-get install git-core $ git clone <repo_url> $ /bin/puppet-run

and if I want to do anything that requires root, I repeat the last line with some sudo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment