Skip to content

Ansible Playbook for setting up a Django app with Nginx, Gunicorn, PostgreSQL, Celery, RabbitMQ, Supervisor, Virtualenv, and Memcached. A Vagrantfile for provisioning a VirtualBox virtual machine is included as well.

amarsahinovic/ansible-django-stack

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ansible-django-stack

Ansible Playbook designed for environments running a Django app. It can install and configure these applications that are commonly used in production Django deployments:

  • Nginx
  • Gunicorn
  • PostgreSQL
  • Supervisor
  • Virtualenv
  • Memcached
  • Celery
  • RabbitMQ

Default settings are stored in roles/role_name/vars/main.yml. Environment-specific settings are in the env_vars directory.

Tested with OS: Ubuntu 12.04.4 LTS x64

Tested with Cloud Providers: Amazon, Rackspace, Digital Ocean

Getting Started

A quick way to get started is with Vagrant and VirtualBox.

Requirements

The main settings to change here is in the env_vars/base file, where you can configure the location of your Git project, the project name, and application name which will be used throughout the Ansible configuration.

I set some default values here using my open-source app, GlucoseTracker, so all you really have to do is type in this one command in the project root:

vagrant up

Wait a few minutes for the magic to happen. Access the app by going to this URL: http://192.168.33.15

Yup, exactly, you just provisioned a completely new server and deployed an entire Django stack in 5 minutes with two words :).

Additional vagrant commands

SSH to the box

vagrant ssh

Re-provision the box to apply the changes you made to the Ansible configuration

vagrant provision

Reboot the box

vagrant reload

Shutdown the box

vagrant halt

Running the Ansible Playbook on existing servers

Create a Playbook for that environment and specify the user accounts to use. See development.yml for an example.

If you only have 1 server, you can skip the other steps below and simply run the Playbook with this command:

ansible-playbook -i server_ip_address_or_hostname, -v playbook.yml --ask-sudo-pass

If you have multiple servers, create an inventory file in the root folder for your environment and add your servers' hostnames or IP addresses there.

For example:

# development

[webservers]
webserver1.example.com
webserver2.example.com

[dbservers]
dbserver1.example.com

Run the Playbook:

ansible-playbook -i development -v development.yml --ask-sudo-pass

If you're testing with vagrant, you can use this command:

ansible-playbook -i vagrant_ansible_inventory_default --private-key=~/.vagrant.d/insecure_private_key -v vagrant.yml

Useful Links

About

Ansible Playbook for setting up a Django app with Nginx, Gunicorn, PostgreSQL, Celery, RabbitMQ, Supervisor, Virtualenv, and Memcached. A Vagrantfile for provisioning a VirtualBox virtual machine is included as well.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%