• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

airtonix/ansible-django: django playbook

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

airtonix/ansible-django

开源软件地址:

https://github.com/airtonix/ansible-django

开源编程语言:

Shell 100.0%

开源软件介绍:

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',
    }
}
...




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap