How to configure SaltStack to provision instances (2/4)

How to configure SaltStack to provision instances (2/4)

How to deploy a web cluster using SaltStack

In this part of this tutorial series we’ll walk you through the process of installing salt-stack (salt-cloud) on a Fuga instance. This will be done using the Clouds.yaml file.

Getting started: installing SaltStack on the saltmaster

First, you will need a single instance (we typically call it the saltmaster) on the Fuga Openstack Platform. To create this instance please refer to the dedicated tutorials: Create a cloud instance and use Ubuntu 18.04 when you select an image.

Second, we need the to use the Clouds.yaml file to let salt-cloud know which OpenStack environment to talk to. Download this file and change the value of password to the password matching the file’s OpenStack credentials.

Setting up the instance

We will begin this step by adding the salt-stack repository to our package manager and its key.

sudo wget -O - | sudo apt-key add -

Now, go to the /etc/apt/sources.list.d/saltstack.list file and add:

deb bionic main

After this, we need to update the package list since we just added a new resource of packages.

sudo apt update

Then install salt-stack and the other packages we need:

sudo apt-get install salt-master salt-cloud python-libcloud

In order to run the Clouds.yaml, we need OpenStack Shade, this is a client library for interacting with OpenStack clouds. We need to install it via pip, so we need to install that first.

sudo apt install python-pip
pip install shade

We also need os-client-config to gather the different configs we are going to use.

pip install os-client-config

As the last part of this step, we need to create a new SSH-Keypair and add it to OpenStack and the saltmaster. We are going to add it to OpenStack using its CLI, of which you can learn more about in the OpenStack CLI tutorials.

We can generate a new pair or use an existing pair. If you want to generate a new pair:


This will generate a new pair for you.

Now log in to the OpenStack CLI, steps to do this can be found in the aforementioned tutorials. And add the Keygen (ours are called id_rsa) to your OpenStack environment with a name (ours are called minion-key):

openstack keypair create --public-key minion-key

Now add both the public and private key to the ~/.ssh directory on your saltmaster.

Because Salt needs to be able to read both the public and private key, we will give these permissions:

sudo chmod 400 ~/.ssh/ ~/.ssh/id_rsa

Getting SaltStack and OpenStack to work together

As mentioned, we are going to use the Clouds.yaml file to specify the OpenStack config for SaltStack. Copy the contents of your Clouds.yaml (including the password) file and paste them in /etc/openstack/clouds.yml.

Defining the Fuga Provider

To configure SaltStack’s sub-program salt-cloud, we need to create some files. Firstly create a new file


Copy paste the following config into the file.

  driver: openstack
  cloud: fuga
  region_name: ams

Defining a Profile

The profile file which we are going to create contains specifications for the minions which will be made. Create the file


Add the following to the file (this will create a c2.medium, with Ubuntu, on the Ipv4-network.):

  provider: fuga-openstack-config
  image: Ubuntu 18.04 LTS
  size: c2.medium
  flavor: c2.medium
  ssh_username: ubuntu
  ssh_key_name: **OPENSTACK KEYPAIR NAME**
    id: bf66495a-4c0d-4725-88c0-462198f1b1fc
  ssh_key_file: **PATH TO PRIVATE KEYPAIR FILE**
    master: **IP OF SALTMASTER**

Replace the user-specific fields (the ones with surrounded with ‘**‘) with your own values.

PATH TO PRIVATE KEYPAIR FILE is as seen from sudo-user so ~/.ssh becomes /home/ubuntu/.ssh.

Creating the servers

Creating the servers is really easy. If we want a server with the name “first-salt-minion”, just run the following command:

sudo salt-cloud -p fuga-cloud-config first-salt-minion

This process will create a new server and install a bunch of things on it, please give it some time. If you want some additional information regarding what is going on (especially shortly after you entered the command), use the log-level flag like so:

sudo salt-cloud --log-level LOG_LEVEL -p fuga-cloud-config first-salt-minion

LOG_LEVEL should be replaced with an item of the following selection: all, garbage, trace, debug, profile, info, warning, error, critical, quiet. The default is set to warning.

Salt will, sequentially, create all the VMs, install salt-minion, and have it connect to the saltmaster.

Next, we will install packages with SaltStack. Follow us to the next tutorial!

Was this article helpful?

Next article:

How to use SaltStack to install packages (3/4)

Installing packages In this part of this tutorial series we’ll walk you through the process of installing packages using salt. The syntax of packages is as follows: nginx: pkg.latest Now, that is already a very simple syntax but what if you wanted to install a list of packages, all part of the same group of packages? Well, Salt has got you covered there as well. Let’s say you want a complete PHP Stack (Nginx, PHP5) - You can use the following syntax:

Improved performance and more features


Start NOW! More information