We used Fabric to automate deploying new versions of the source code to our servers. But provisioning a fresh server, and updating the Nginx and Gunicorn config files, was all left as a manual process.
This is the kind of job that’s increasingly given to tools called “Configuration Management” or “Continuous Deployment” tools. Chef and Puppet were the first popular ones, and in the Python world there’s Salt and Ansible.
Of all of these, Ansible is the easiest to get started with. We can get it working with just two files:
pip2 install --user ansible # Python 2 sadly
An “inventory file” at deploy_tools/inventory.ansible defines what servers we can run against:
root ansible_ssh_port=6666 ansible_host=127.0.0.1
(The local entry is just an example, in my case a Virtualbox VM, with port forwarding for ports 22 and 80 set up.)
Next the Ansible “playbook”, which defines what to do on the server. This uses a syntax called YAML:
Deadsnakes PPA to get Python 3.6
make sure required packages are installed