Table of Contents
[warning]
Status: Deprecated
This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:
Reason:
Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.
See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.
Introduction
This tutorial builds on How To Install Salt on Ubuntu 12.04 | the cloud provider and aims to provide the reader with a simplified, basic setup of an operable Salt Cloud master server. the cloud provider users can then use this employ to automate the process of creating 1, 2 or a fleet of cloud servers.
Total Infrastructure Management
Salt Stack is an open-source cloud deployment, configuration management, remote execution & monitoring package. You may not have heard of Salt, but you might be familiar with Puppet or Chef. Salt is a similar tool, but it is relatively lightweight in terms of resources and requirements, and a growing number of users consider it *much* easier to use. Tools like Salt, Puppet and Chef allow you to issue commands on multiple machines at once, as well as install and configure software. Salt has two main aspects: (i) configuration management and (ii) remote execution. Cloud deployment is left to Salt Cloud.
Salt Cloud is a public-cloud provisioning tool designed to automate the deployment of public cloud servers. It integrates Salt with the cloud provider's application programming interface (API) in a clean way – and (i) creates; (ii) provisions & (iii) manages droplets (i.e. cloud or virtual private servers) via virtual machine maps and profiles. cloud servers can be created individually or in large groups and can be provisioned and fully managed, without ever needing to be logged into. From deploying single virtual machines, to mapping and provisioning entire clouds, Salt Cloud is as scalable as you need it to be.
Prerequisites
First, consult How To Install Salt on Ubuntu 12.04 | the cloud provider and create a Salt master/minion on your VPS.
Any server accessible from the public Internet should be security hardened and your Salt master is no exception:
- Change your SSH port from the default Port 22 to a random port below 1024, as described in Step Five of Initial Server Setup with Ubuntu 12.04;
The Salt master communicates with the minions using an AES-encrypted ZeroMQ connection. These communications are done over TCP ports 4505 and 4506, which need to be accessible on the master *only*.
- Configure a firewall and make sure to open your custom SSH port and TCP Ports 4505 & 4506;
The default firewall configuration tool for Ubuntu is ufw. To open the Salt ports, simply execute:
sudo ufw allow [custom SSH port below 1024]/tcp
sudo ufw allow salt
sudo ufw enable
sudo ufw status verbose
Either disable password logins or deploy Fail2ban & DenyHosts.
Salt Cloud uses public key encryption to secure the communication between the Salt master and the cloud provider. Therefore, create a directory on your master in which to store your SSH keys:
sudo mkdir /keys
Next, execute:
sudo ssh-keygen -t rsa
The system will respond with <code>Enter file in which to save the key (/root/.ssh/id_rsa):</code>. Copy and paste:
/keys/the cloud provider-salt-cloud
Press "Enter" on your keyboard. The system will display <b>Enter passphrase (empty for no passphrase):</b>, asking you to enter an *optional* password. Do not enter a passphrase; instead, tap the "Enter" key twice.
Your new public (SSH) key is now located in "keys/the cloud provider-salt-cloud.pub." Finally, execute:
cat /keys/the cloud provider-salt-cloud.pub
Copy and paste the public key into your the cloud provider Control Panel, as outlined in Step Three of How To Use SSH Keys with cloud servers (save the name of the public key in your Control Panel as <b>the cloud provider-salt-cloud.pub</b>).
—
Verify that your Salt master's hostname and FQDN are properly set. *See* Setting the Hostname and Fully Qualified Domain Name (FQDN) on Ubuntu 12.04.
—
Salt Stack is built with the Python programming language; so, we'll need <b>pip</b> (a package management system used to install and manage software packages written in Python). In addition, despite being available via Python's repositories, we'll be downloading the Salt Cloud package from Salt Stack's GitHub repository.
To install <code>pip</code> and <code>git</code> on your system, execute:
sudo apt-get -y install python-pip git
Install Salt Cloud Dependencies
—
First, execute:
sudo apt-get -y install python-m2crypto
Then, execute:
sudo pip install pyzmq PyYAML pycrypto msgpack-python jinja2 psutil salt
Next, execute:
sudo pip install apache-libcloud
Install Salt Cloud
—
Finally, execute:
sudo pip install git+https://github.com/saltstack/salt-cloud.git#egg=salt_cloud
Verify Salt Cloud was successfully installed by executing:
salt-cloud –version
Configure Salt Cloud
—
Salt Cloud runs on a module system similar to the main Salt project; and, by default, uses PyYAML syntax for its template files – but numerous other templating languages are available as well. When creating your configuration files, be sure to follow the proper formatting techniques for YAML, which involves two spaces instead of tabs.
An online YAML parser is available when troubleshooting syntax issues with YAML files.
I. Core Configuration
—
The core configuration of Salt Cloud is handled in the cloud configuration file. This file is comprised of global configurations that affect all cloud providers in your system. In addition, the cloud file is where the minions that are created derive their configuration.
Create the cloud configuration file by executing (obviously, you can use whichever text editor you wish; but this guide assumes that you have installed the vim text editor):
sudo vim /etc/salt/cloud
On your keyboard, tap on the <b>i</b> key; use the arrow keys to navigate the text area; and copy & paste or create your cloud file so that it resembles the example below (replacing <code>master.yourdomain.tld</code> with the FQDN of your Salt master):
provider: do
minion:
master: master.yourdomain.tld
To save and exit, tap the <b>Esc</b> key on your keyboard, followed by these keystrokes: 1) : 2) w 3) q 4) Enter.
For further customization, additional miscellaneous options, that can be passed in the core configuration file are available.
Cloud Provider Modules
—
Next, create two new directories:
sudo mkdir /etc/salt/{cloud.profiles.d,cloud.providers.d}
These new directories will hold the the cloud provider-specific YAML configuration files.
II. the cloud provider Cloud Provider Configuration
—
The the cloud provider *cloud provider* configuration is used to control access to your cloud account. Create the the cloud provider cloud provider configuration file by executing:
sudo vim /etc/salt/cloud.providers.d/the cloud provider.conf
Tap on the <b>i</b> key; use the arrow keys on your keyboard to navigate the text area; and copy & paste or create your the cloud provider.conf file so that it resembles the example below:
do:
provider: the cloud provider
client_key: YourClientIDCopiedFromControlPanel
api_key: YourAPIKeyCopiedFromControlPanel
ssh_key_name: the cloud provider-salt-cloud.pub
ssh_key_file: /keys/the cloud provider-salt-cloud
To save and exit, tap the <b>Esc</b> key on your keyboard, followed by these keystrokes: 1) : 2) w 3) q 4) Enter.
cloud provider API
—
Using Salt Cloud with the cloud provider requires a <b>client_key</b> and an <b>api_key</b>. These can be found in the the cloud provider Control Panel, under the "API Access" tab.
Now, create an API key for your account by following the steps outlined in How To Use the cloud provider API. You will need to copy and paste both your the cloud provider <code>Client ID</code> and <code>API Key</code> in the *cloud provider* configuration file, described above.
Interacting with the API
—
After you configure the the cloud provider provider in <code>/etc/salt/cloud.providers.d/the cloud provider.conf</code>, you gain access to the following commands:
sudo salt-cloud –list-images do
sudo salt-cloud –list-sizes do
sudo salt-cloud –list-locations do
sudo salt-cloud –help
The output from these commands are important because it provides the variables needed to build our virtual server profiles.
III. the cloud provider Cloud Profile
—
Create the the cloud provider cloud profiles for your server fleet by executing:
sudo vim /etc/salt/cloud.profiles.d/the cloud provider.conf
Now, on your keyboard tap on the <b>i</b> key; use the arrow keys to navigate the text area; and copy & paste or create your the cloud provider.conf file so that it resembles the example below:
ubuntu_512MB_ny2:
provider: do
image: Ubuntu 12.04.4 x64
size: 512MB
location: New York 2
private_networking: True
ubuntu_1GB_ny2:
provider: do
image: Ubuntu 12.04.4 x64
size: 1GB
location: New York 2
private_networking: True
ubuntu_2GB_ny2:
provider: do
image: Ubuntu 12.04.4 x64
size: 2GB
location: New York 2
private_networking: True
#[profile_alias_of_your_choosing]:
To save and exit, tap the <b>Esc</b> key on your keyboard, followed by these keystrokes: 1) : 2) w 3) q 4) Enter.
In addition to the examples provided, Salt Cloud can accommodate multiple configuration files, which allows for more extensible configuration and plays nicely with various configuration management tools, as well as version control systems.
OS Support for Cloud VMs
—
Salt Cloud works primarily by executing a script on the newly-provisioned droplets as soon as they become available. By default, the script that is used is the salt-bootstrap script, unless a different deploy script is declared in the cloud profile. The preferred method (as of Salt Cloud v0.8.9) is currently to use the default salt-bootstrap script. If the salt-bootstrap script does not meet your needs, you may pass Deploy Script Arguments or write your own.
Advanced Topic
—
A number of options exist when creating your VPS that are beyond the scope of this article. After you feel comfortable with the foundational principles outlined in this tutorial, you may want to learn about creating a more complex setup with a map file. The map file allows for a number of virtual machines to be created and associated with specific profiles.
Provision a New Cloud Server!
—
To create a new cloud server, execute (replacing <b>hostname</b> with any hostname of your choice):
sudo salt-cloud –profile ubuntu_512MB_ny2 hostname
If all goes well, you should have a newly-provisioned server, bootstrapped with Salt minion (the new minion's SSH keys will automatically be added to the Salt master). If you would like to provision multiple virtual machines from the same profile, you can do so with a single command, e.g.
sudo salt-cloud -p ubuntu_1GB_ny2 hostname1 hostname2 hostname3
(Note that <code>–profile</code> and <code>-p</code> are interchangable.)
Minion Configuration
—
To configure your new fleet of cloud servers, consult: How To Create Your First Salt Formula | the cloud provider.
Destroy a Minion
—
There are various options that can be passed when executing a Salt Cloud command. For example, to destroy a particular minion simply execute:
sudo salt-cloud -d hostname
Additional Resources
—
- Salt Starters (a place to find and share Salt-Stack-related code, such as state trees or custom modules);
- All the cloud provider Configuration Management articles.
As always, if you need help with the steps outlined in this How-To, look to the the cloud provider Community for assistance by posing your question(s) below.