Salt Sandbox is a multi-VM Vagrant-based Salt development environment used for creating and testing new Salt state modules outside of your production environment. It's also a great way to learn firsthand about Salt and its remote execution capabilities.
Salt Sandbox will set up three separate virtual machines:
- master.example.com - the Salt master server
- minion1.example.com - the first Salt minion machine
- minion2.example.com - the second Salt minion machine
These VMs can be used in conjunction to segregate and test your modules based on node groups, top file environments, grain values, etc. You can even test modules on different Linux distributions or release versions to better match your production infrastructure.
##Requirements
To use salt sandbox, you must have the following items installed and
working:
- VirtualBox
- Vagrant, version 1.8.1 or later
- vagrant-hostmanager
Optionally, there are some Makefile rules included for convenience
that handle key generation and creating a simple salt state tree. To
use the included Makefiles, you'll want GNU make. The rules assume
that openssl is available to generate the private and public keys.
The salt sandbox has been designed for and tested with vagrant base boxes
running:
- CentOS 6.7, 5.7
- Ubuntu 10.04 - Lucid Lynx
...although itshould work just fine with other distributions and releases.
Make sure you have a compatible vagrant base box (if you don't have one
already, it will download a 64-bit CentOS6.7 box for you), and then you
should be good to clone this repo and go:
$ git clone git://github.com/elasticdog/salt-sandbox.git
$ cd salt-sandbox/To bring up the salt sandbox environment, issue the following command:
$makeThe following tasks will be handled automatically:
- The
salt masterdaemon will be installed and enabled on the master machine. - The
salt miniondaemon will be installed and enabled on all three machines. - A private network will be set up with all machines knowing how to communicate with each other.
- All
minionpublic keys will be automatically accepted by themasterserver. - The
masterserver will utilize thetop.slsfile andbase/directory that exist outside of the VMs (in your salt-sandbox Git working directory) by utilizingvirtualbox's shared folder feature.
All of this is handled using vagrant's provisioning capabilities and is
controlled by the Vagrantfile. In theory, you
should never have to touch any of that code directly unless you're working to
improve salt sandbox.
If you wish to change the domain name of the VMs (it defaults to
example.com), edit the "domain" variable at the top of Vagrantfile and at the top of keys/Makefile and
reload the machines:
$ make -C keys domain=otherdomain.com
$ vim Vagrantfile
$ vagrant reloadTo start developing a salt module, just create the standard module structure
under base/ in your salt sandbox working directory (an example
helloworld module should exist there already). This directory is
automatically in the salt master server's file\_roots path, and any changes
will be picked up immediately.
$ mkdir -p base/mymodule
$ vim base/mymodule/init.slsTo have your module actually applied to one or more of the minions, edit
the top.sls file and specify how it should be used during state
execution...that's it!
To log on to the virtual machines and see the result of your salt modules, just
use standard Vagrant Multi-VM Environment
commands, and provide the proper VM name (master, minion1, or minion2):
$ vagrant ssh masterThen instruct all minions to execute a highstate call and apply any applicable
modules:
[vagrant@master ~]$ sudo salt '*' state.highstateSalt Sandbox is provided under the terms of The MIT License.
Copyright © 2016, Will Estes.
Copyright © 2012, Aaron Bull Schaefer.