SaltStack Lab in Vagrant

Today I have published a really simplistic SaltStack lab for Vagrant to GitHub:

https://github.com/xanmanning/vagrant-salt-example

Since being subjected to CFEngine (shudder), I have been very keen to try out other configuration management offerings. I had previously tried Ansible, that’s great and all, however there are advantages to agent based systems, particularly the scalability.

Salt stands out for me, because like Ansible, configuration is done in YAML - this is fantastically easy to use! Also, Salt can be easily extended with custom modules! It’s standard stuff: Python, Fabric and Jinja2. It’s quick, scalable and flexible. It’s simple.

Using Vagrant

Salt is actually quite easy to get running in Vagrant, if your Vagrantfile defines Salt as the provisioning method then Vagrant will go off and install the Salt Master and Salt Minions to whichever VM you define. Unlike Ansible, you don’t need Salt on your host machine.

A master configuration would likely look like the below in your Vagrantfile:

master.vm.provision :salt do |salt|
    salt.install_master = true
    salt.install_type = "stable"
    salt.master_config = "salt/master"
    salt.minion_config = "salt/minion"
    salt.masterless = true
end

Where master_config and minion_config point to the configurations in your Vagrant directory.

Example Configuration

The above repository includes a simple configuration of 1 master and 2 minions. One minion will be configured as an App server (running SQLBuddy), the other as a Db server (Running MySQL Server).


    +---------+     +--------+
    |   App   | --> |   Db   |
    +---------+     +--------+
         ^               ^
         |               |
         +---------------+
                 |
                 |
             +--------+
             | Master |
             +--------+

Fire it up!

To get started with my example, simply run:

$ git clone https://github.com/xanmanning/vagrant-salt-example && cd ./vagrant-salt-example

Then:

$ vagrant up

Wait for the VMs to finish provisioning, you will get output similar to the below:

Salt Provision

Once you are done, you can visit your app server: http://10.10.8.3/ and login to the database with the below details:

  • Host: db.salt.local
  • User: salt
  • Pass: s4ltm4$t3r!

SQLBuddy managed with Salt

Play

If you want to play about with Salt, a good way to get your hands dirty is to SSH into the master and start editing the salt state files:

$ vagrant ssh master

From here, you can find all the states in /srv/salt/base, with some tweaking you can make some awesome changes!

Vim Editor

Then push these changes out by running:

$ sudo salt '*' state.highstate

This will (by default) present you with the output of your salt states:

Highstate