Image for post
Image for post

Salt DevKit with External Formulas

Local Development with Vagrant using external Salt formulas

Every popular change configuration worth their salt has some form of modularity. Chef has cookbooks, Puppet has modules, Ansible has roles, and Salt Stack has formulas.

Tool Prerequisites

These are the tools used in this guide:

  • VirtualBox (recommended) is cross-platform (win, linux, mac) that allows you to run virtual machines. Other virtual machine system can be used, such as Hyper-V for Windows 10 Pro or KVM (libvrt) on Linux. This guide uses VirtualBox as it is open source and cross platform.
  • Bash Shell (recommended) is not strictly required, but the commands in this tutorial are tested and oriented toward bash. [Note: this is default in mac OS and popular Linux distros, or msys2 with Windows].

The Guide

In this guide we’ll use an external nginx-formula to install a basic nginx server with default site. We’ll this run this locally with masterless Salt.

Step 1: Create Project Area

If you are using Bash, you can quickly create the directory and file structure with the following commands:

# create directory structure
-p ~/salt-devkit-formula/{config,roots/{pillar,salt}}
# create files
config/minion.yaml \
roots/{pillar,salt}/top.sls \
roots/pillar/nginx.sls \
├── Vagrantfile
├── config
│ └── minion.yaml
└── roots
├── pillar
│ ├── nginx.sls
│ └── top.sls
└── salt
└── top.sls

Step 2: Create Vagrant Configuration

Edit the Vagrantfile configuration with the following content:

Step 2: Create Minion Configuration

We need to configure a local configuration to tell Salt Minion to use the nginx formula. Edit the config/minion.yaml file with the following contents.

Step 3: Create Salt States

We want to create our top state for our single node and tell it to use the nginx state that should now be available from the formula. Edit the roots/salt/top.sls file:


Step 4: Create Salt Pillars

Similarly to top state file, we also want to tell our top pillar to use nginx values. Edit the roots/pillar/top.sls and add the following:


Step 2: Create, Provision, and Test

Now we are ready to bring up the environment and provision it with using a state from an external module.

vagrant up --no-provision
vagrant provision
curl localhost:8080

Step 3: Clean Up

You can remove everything from the host with the command:

vagrant destroy 

Using Python 3

Salt Stack currently (Feb 2020) by default uses Python 2, but Python 2 is deprecated as of 2020. The Vagrantfile configuration supports Python 3, on a new system that has not been provisioned, you can use Python 3 with the following command:

vagrant up --no-provision
PYTHON=python3 vagrant provision

Related Article

A while back I created a series to demonstrate using different change configuration tools with Vagrant provisioners, where one of these including using Salt Stack:



Salt Formulas


That is all there is to this: a brief guide on how create a local Salt Stack development environment and integrate use of external formulas.

Written by

Linux NinjaPants Automation Engineering Mutant — exploring DevOps, Kubernetes, CNI, IAC

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store