Sunday, April 12, 2015

Vagrant and Salt

I’ve recently discovered Vagrant (https://www.vagrantup.com/). It has changed my developer life. Having consistent environments for development and testing is ideal, and Vagrant gives us that. Before it was much more difficult to get everyone up and running, but now its as easy as a single Vagrant file.

The next thing I recently discovered is Salt (http://saltstack.com/). I don’t know much about Salt, but I want to. I have a side project I’m working on that will greatly benefit from it. 

So naturally, I wanted to use Vagrant to experiment with Salt. Vagrant even has built in support for Salt. But one thing I noticed is that there is not a simple example of running Vagrant and Salt, with a “master and minion”. The examples I found were either running “masterless”, or they have the master and minion on the same VM.

So after a bit of research and experimentation, I figure out how to set up a separate master and minion, in Vagrant. It takes care of the keys also. 

There are two files involved, the Vagrantfile and a salt_minion.conf. Here they are:

Vagrantfile

Vagrant.configure(2) do |config|
    config.vm.box = "ubuntu/trusty64"
    config.vm.box_url="https://atlas.hashicorp.com/ubuntu/boxes/trusty64"

    config.vm.define "master" do |infrastructure|
        infrastructure.vm.hostname="master"

        infrastructure.vm.network "private_network", ip: "192.168.0.128"

        # Make this bad boy into the salt-master
        infrastructure.vm.provision :salt do |salt|
            salt.install_master=true
            salt.no_minion=true
        end

        infrastructure.vm.provision "shell", inline: <<-SHELL
  rm -f /vagrant/minion.pem /vagrant/minion.pub
  salt-key --gen-keys=minion
  cp minion.* /vagrant/
  cp minion.pub /etc/salt/pki/master/minions/minion
        SHELL
    end

    config.vm.define "minion" do |minion|
        minion.vm.hostname="minion"

        minion.vm.network "private_network", ip: "192.168.0.2"

        minion.vm.provision :salt do |salt|
            salt.install_master=false
            salt.no_minion=false
            salt.minion_key = "./minion.pem"
            salt.minion_pub = "./minion.pub"
            salt.minion_config = "./salt_minion.conf"
        end
    end
end

salt_minion.conf
master: 192.168.0.128
id: minion
file_client: remote

No comments:

Post a Comment