Example Salt states for provisioning the infrastructure of a REST API implemented in Python with SQL persistence.
The DB used is PostgreSQL and runs in a single machine.
The API runs on a single machine.
The API uses the database from the DB machine.
The API is configured as a WSGI application and executed by gunicorn.
The gunicorn instance is watched by the supervisor service.
Nginx runs as a reverse proxy of gunicorn.
Salt runs on:
- A Salt master machine
- The REST API machine (running a Salt minion)
- The DB machine (running a Salt minion)
- Python
- Ruby
- A VM Manager, either: ** VirtualBox or ** libvirt with vagrant-libvirt Vagrant plugin installed(vagrant plugin install vagrant-libvirt)
- Vagrant
The Vagrantfile already exist in this project. In order to create the VMs execute:
vagrant up
When finished working on this project, execute:
vagrant destroy -f
file_roots
is set to directory saltstack/salt
and pillar_roots
to saltstack/pillar
, both settings defined in saltstack/etc/master
Log into Salt master:
vagrant ssh master
Change to root user:
sudo su
Accept the keys of Salt minions:
salt-key -A
Provision all minions:
salt '*' state.apply
All the actions described below are performed automatically by Salt during provision.
The application code is cloned from a Github repository into a local directory.
The application relies on an .env
file, which is filled with information read by Salt from Pillar and Mine.
Salt Pillar contains DB credentials.
Salt Mine provides the IP address of each machine, in particular the IP address of the DB server. Salt uses the DB IP address informed by Mine and fills the DB host parameter in the .env
file.