21 September 2013

Updated: 18 May 2014

Setting up a local machine with Saltstack

Debian Precursor

Fresh Debian installs don't come with sudo, so it's preferable to install and configure that for the current user first. The Debian docs on sudo are good, but it basically boils down to two things - install sudo and add your user to the sudoers group:

$ su
$ apt-get install sudo
$ usermod -aG sudo mafro

You'll probably need to log out and log in again for the group permissions to take effect.

Bootstrap Salt

Before we can install salt, we're going to need git:

$ sudo apt-get install git

The awesome salt-bootstrap project then does the hard work for us:

$ sudo -s
$ wget -O - http://bootstrap.saltstack.org | sh

We end up with the salt-minion and salt-common packages installed, which is all we need to run Salt locally.

Dotfiles

I wrote a salt state tree which I include with my dotfiles on Github, so next I need to jump through a couple of SSH key auth hoops before I can clone my dotfiles to the local machine.

Generate a new SSH key, as your login user:

$ ssh-keygen -t rsa
$ mv ~/.ssh/id_rsa ~/.ssh/github.$(hostname).pky
$ echo -e "Host github.com\n\tIdentityFile ~/.ssh/github.$(hostname).pky" > ~/.ssh/config
$ echo -e "\tStrictHostKeyChecking no" >> ~/.ssh/config
$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2E .. snip .. 15UlA85gxWN1rFb root@hostname

Now copy the public component of the key we've generated into a new deploy key on your dotfiles repo on Github (at https://github.com//dotfiles/settings/keys). Give it an obvious name to remind you where that key is being used (like the hostname of the machine).

$ git clone git@github.com:mafrosis/dotfiles.git

An elementary salt config

Included with my dotfiles is a basic salt-minion config, which works great for setting up a single machine locally:

file_client: local

id: <hostname>

grains:
  user: mafro

fileserver_backend:
  - roots
  - git

file_roots:
  base:
    - /home/mafro/dotfiles/salt

pillar_roots:
  base:
    - /home/mafro/dotfiles/salt/pillar

gitfs_remotes:
  - git@github.com:mafrosis/salt-formulae.git

Install that config to /etc/salt/minion.d/, and ensure that something is in matching hostname or id in your top.sls1 before you run the highstate:

$ sudo salt-call --local state.highstate

:x


Tagged in tekkers devops