Giter Site home page Giter Site logo

ansible-django's Introduction

Ansible Django Deployment playbook.

MIT Licensed.

This playbook works with (or will aim to work with) the following technologies:

  • Django
  • Git
  • uWsgi
  • Nginx
  • PostgreSQL
  • Celery
  • Haystack
  • Elastic Search
  • Redis

I encourage pull requests towards this regard

Todo

  • Security

    • close all ports and open only those required
    • dbservers:
      • only allow access into postgres port from appservers ip addresses
  • Database Node

    • celery
    • haystack
    • elasticsearch
  • Monitoring

    • Nagios
  • Auto Scaling

    • nagios triggers to automate ansible scaling

Installation

  • git clone this repo to a sensible location
  • edit ~/.bash_rc (or other such file) to include an alias to the play script. alias playbook='~/Dev/ansible/play'
  • copy the inventory directory to your django project source tree (see below) and put all sensitive information in this folder (assuming your project is private).
  • copy the Vagrantfile to the same location.
  • modify line 51 to point at this repo you cloned: ansible.playbook = "~/Dev/ansible/playbook/site.yml"

Minimum Django Applications

I make some assumptions about the packages that you'll use:

  • django-postgrespool==0.2.4
  • hiredis==0.1.1
  • django-redis-cache==0.10.0

Running deployments

just a small example of things you can do :

playbook deployment/inventory/production all
playbook deployment/inventory/production webservers
playbook deployment/inventory/production dbservers
playbook deployment/inventory/production webservers --tags=pip

Testing deployments

  • install virtualbox first
  • edit inventory/vagrant to suit your desired scenerio
  • get the machines created
$ pwd
/home/zenobius/Dev/websites/my-new-project/

$ cd deployment

$ ls -algh
total 4.0K
drwxrwxr-x 1 zenobius   56 Oct 23 08:57 .
drwxrwxr-x 1 zenobius   96 Oct 23 08:56 ..
drwxr-xr-x 1 zenobius   44 Oct 23 07:21 inventory
-rw-rw-rw- 1 zenobius 2.0K Oct 23 08:47 Vagrantfile

$ vagrant up
... snip hundreds of lines about creating virtualmachines ...

Then begin provisioning process

$ vagrant provision
... snip hundreds of lines about ansible playbook output ...

Using the playbook

  • firstly, make sure your project directory layout matches the layout described below
  • ensure you've followed the steps above in Installation.
  • in your deployment directory :

For the entire infrastructure

$ playbook inventory/production site

To setup the database servers

$ playbook inventory/production dbservers

To run the tasks dealing with only installed/updating packages

$ playbook inventory/production appservers --tags=packages

Django Project Layout

In your django project, you should organise your settings module like so :

  • git_root
    • deployment/
      • inventory
    • requirements/
      • base.list
      • live.list
      • test.list
      • local.list
    • application/
      • __init__.py
      • manage.py
      • base/
        • __init__.py
        • wsgi.py
        • settings/
          • modules/
            • __init__.py
          • __init__.py
          • default.py
          • local.py
          • live.py

project_root/manage.py

#!/usr/bin/env python
#
# file: project_root/manage.py
#
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "base.settings.local")
    from django.core.management import execute_from_command_line
    execute_from_command_line(sys.argv)

project_root/base/wsgi.py

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "base.settings.live")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

project_root/base/settings/live.py

from .default import *
from .modules.db import *
from .modules.cache import *
from .modules.celery import *

DEBUG = False
TEMPLATE_DEBUG = DEBUG

...

project_root/base/settings/local.py

from .default import *


DEBUG = True
TEMPLATE_DEBUG = DEBUG

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'db.sqlite3',
    }
}
...

ansible-django's People

Contributors

airtonix avatar tback avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.