Skip to content

Ansible playbook to deploy a Django project - demo for my talk at PyCon Italy 2017 (PyCon Otto)

Notifications You must be signed in to change notification settings

marco-santamaria/django-ansible-deploy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demonstrative Ansible playbook to deploy a Django project

For PyCon 8, Florence, April 2017

The pycon8 folder includes a single Django project having a single app, a single model and a single view. That project features the minimal setup required to make it easy deployable with PIP and uses environment variables for configuration.

The deploy folder contains a bunch of Ansible playbooks to configure the servers and deploy the project using the following technologies:

  • CentOS 7
  • NGiNX
  • uWSGI
  • Python 3.6
  • PostgreSQL

To install a local development environment clone the repo and create a virtual environment with Python 3.6, then run the command:

pip install -r requirements/local.txt

To create an installation bundle in the deploy/files folder you can run the following command:

invoke build --bundle

To create two local CentOS virtual machines use the provided Vagrantfile tested with the VirtualBox provider:

cd deploy
vagrant up

To run the Ansible playbook a [virtual] environment with Python 2.7 is required, until Ansible will be fully compatible with Python 3.

To configure the project for the local environment create and edit the dotenv file in the deploy/files folder copying it from the .env.example file:

cp .env.example deploy/files/pycon8.env

Then to deploy on the two local Vagrant boxes run the main playbook:

ansible-playbook -i hosts/local all_servers.yml --extra-vars "pycon8=0.1.0" -vvv

The two CentOS 7 machines will be configured as web server and database server and the project will be deployed using the installation bundle.

Using the git_repo variable it is possible to deploy in the target machines directly from GIT and PyPI:

ansible-playbook -i hosts/local web_servers_git.yml --extra-vars "pycon8=master" -vvv

Using tags it is possible to perform a deploy, skipping all the configuration steps and without any internet access:

ansible-playbook -i hosts/local web_servers.yml --extra-vars "pycon8=0.1.0" --tags=deploy -vvv

About

Ansible playbook to deploy a Django project - demo for my talk at PyCon Italy 2017 (PyCon Otto)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published