How to deploy a web cluster using SaltStack
Getting started: installing SaltStack on the salt master
First, you will need a single instance (we typically call it the saltmaster) on the Cyso Openstack Platform. The saltmaster needs to be able to reach the internal (private) IP addresses of the new instances. To install this VM, please follow the tutorials at Create a cloud instance and use Ubuntu when you select an image. At the moment, Ubuntu 14.04 has salt 0.17.5. Unfortunately, that version is already outdated and we need some features in the newer version. As such, we will be using the Ubuntu provided PPA for now:
sudo add-apt-repository ppa:saltstack/salt sudo apt-get update sudo apt-get install salt-master salt-cloud python-libcloud
Getting SaltStack and OpenStack to work together
To make SaltStack capable of provisioning and deploying machines, we can use a sub-program salt-cloud. First, we need to define a cloud provider. In this case that is going to be OpenStack. To define this provider, go to /etc/salt/cloud.providers.d and open a new file, openstack.conf, in your favorite editor. (We use the editor command instead of vi/nano etc. because you can configure what editor it will use!)
Set the contents of this file to the following:
cyso-openstack-config: minion: master:
identity_url: http://horizon.api.fuga.io:5000/v2.0/tokens compute_name: nova protocol: ipv4 compute_region: cystack user: password: tenant: provider: openstack insecure: true
Let's take a look at this file line by line.
This is the name of the cloud provider. This is used only within salt config files.
minion: master: <master IP address>
This specifies the master ip / hostname that the new webcluster connects to.
This variable specifies the OpenStack Identity URL. The OpenStack Identity URL can be located in your Horizon Dashboard under Access & Security - API Access
compute_name: nova protocol: ipv4 compute_region: cystack
Cloud profiles are Salt's way of determining the Image, Size and ssh details it needs to use. Our profile is very basic. Go to the folder /etc/salt/cloud.profiles.d/ and open a new file:
editor stack_micro.conf stack_micro: # Just a name - used internally by salt. provider: cyso-openstack-config # this is the provider we specified earlier. size: c1.micro # the instance size. image: "0c795dbb-cb84-44fe-b716-18c5eaa4ff13" # Image ID ssh_key_file: /home/youruser/.ssh/id_rsa #ssh private key that can be used to login to the newly created servers. ssh_key_name: my-ssh-key #SSH Key name as defined within openstack. ssh_interface: private_ips #By default, all the new nodes will have a private network within Cyso's network. ssh_username: ubuntu #The ubuntu image requires you to use the ubuntu username when logging in.
If you have multiple networks you will also need to define the network id. Example:
networks: - fixed: - d36ffd46-bf80-4d98-89ae-21e27348241f
Defining a map file
The last component for the provisioning of the new cloud instances is a map file. The map file is used by salt to link the newly created profile to the to-be-created instances. First go to /etc/salt/cloud.maps.d and open a new file. An example map file could be:
editor example.conf stack_micro: - web1.example.com - web2.example.com - web3.example.com - db1.example.com
The map file is pretty straightforward. First we tell it what profile to use (stack_micro) and then specify a list of hostnames to create. Now, let's get to the fun part!
Creating the servers
Creating the servers is really easy. Just run the following command:
salt-cloud -m <map file>
If you followed our example exactly, the full command would be:
salt-cloud -m /etc/salt/cloud.maps.d/example.conf
Salt will, sequentially, create all the VM's, install salt-minion and have it connect to the salt master.