SlideShare a Scribd company logo
1 of 17
Download to read offline
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
Deploying Django with Ansible
Andrew	
  Mirsky	
  
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
For	
  development:	
  
~/myproject > ./manage.py runserver
Validating models...
0 errors found
May 30, 2014 - 11:31:08
Django version 1.6.2, using settings 'settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
	
  
For	
  produc0on:	
  
/var/www > sudo ./manage.py runserver 0.0.0.0:80 /dev/null 2>&1 &
/var/www >
	
  
running a django server
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
production setup
•  One	
  or	
  more	
  applica=ons	
  (aka	
  virtual	
  servers)	
  
•  Mul=ple	
  applica=on	
  processes	
  &	
  monitoring	
  
•  Data	
  storage	
  &	
  retrieval	
  (aka	
  databases)	
  
•  Security	
  
•  Maintainable,	
  robust,	
  scalable	
  
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
basic setup
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
components
•  webservers	
  
–  apache	
  
–  nginx	
  
–  cherokee	
  
•  interpreter	
  
–  mod_wsgi	
  
–  uwsgi	
  
–  gunicorn	
  
•  databases	
  
–  postgres	
  
–  mysql	
  
–  [	
  mongodb,	
  couchdb,	
  cassandra	
  ]	
  
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
scalable setup
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
scalable, redundant setup
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
ansible
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
ansible for single commands
> pip install ansible
> ansible webservers –i myinventory -a ”touch /srv/foo.txt && /sbin/reboot" -f 10
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
anatomy of an inventory
> cat inventory
# file: inventory
[webservers]
app[0:4].mirsky.net ansible_ssh_private_key_file=~/.ssh/key1.pem
[dbservers]
db[0:2].mirsky.net ansible_ssh_private_key_file=~/.ssh/key2.pem
[mytotalsite:children]
webserver
dbservers
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
ansible playbooks
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
building playbooks
> pip install ansible-role-manager
> arm help
usage: /Users/andrew/env/arm/bin/arm [-h] {freeze,help,init,install,uninstall} ...
positional arguments: {freeze,help,init,install,uninstall}
freeze produces dependencies file for this playbook based on...
help an alias for calling `-h` on any subcommand
init initialize directory structure & files
install install playbook role
uninstall remove a role from the library of dependencies
> arm init -p mydjangoplaybook
ansible playbook created successfully
> arm install git+https://github.com/mirskytech-ansible/role-postgres.git
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
anatomy of a playbook
> cat mydjangoplaybook/mysite.yml
 ## file: mysite.yml !!
  !!
## usage: ansible-playbook -i <inventory file> mysite.yml !!
- hosts: webservers
vars: webservers
  - project: mydjangoproject
 
  roles:
      - cherokee
      - postgres
 
tasks:
 
  - name: install uwsgi & postgres modules
    sudo: yes
    pip: name="uwsgi psycopg2”
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
anatomy of a role
> cat roles/cherokee/tasks/main.yml
---
## file: cherokee/tasks/main.yml
 - name: add cherokee ppa
   sudo: yes
   command: mkdir /srv/www && chgrp www-data /srv/www
 - name: add cherokee ppa
   sudo: yes
   apt_repository: repo="ppa:cherokee-webserver" state="present"
   register: ppa_add
   ignore_errors: true
 
  - name: package install
    sudo: yes
    apt: pkg={{ item }} state=present update_cache=yes
    with_items:
      - cherokee
      - libcherokee-mod-libssl
    register: apt_install
    ignore_errors: true
    when: ppa_add|success
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
anatomy of a task
  - name: create uwsgi config file
    sudo: yes
    template: >
        src=templates/uwsgi.ini.j2
        dest=/srv/www/{{ project }}/uwsgi.ini
        group='www-data'
        mode=660
register: this_task_rc
    ignore_errors: true
    when: previous_task_rc|success
> cat templates/uwsgi.ini.j2
# uwsgi.ini for {{ hostname }}
 
[uwsgi]
vhost = true
master = true
enable-threads = true
processes = 2
wsgi-file = /srv/www/{{ project }}/webapp/wsgi.py
virtualenv = /srv/env/{{ project }}
chdir = /srv/www/{{ project }}
touch-reload = /srv/reload/{{ project }}
pythonpath = /srv/www/{{ project }}
daemonize = /var/log/{{ hostname }}.log
post-buffering = 32768 Ansible’s	
  Template	
  Module	
  Docs	
  
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
anatomy of a module
> cat library/mymodule_command
from ansible.module_utils.basic import *
def main():
# module arguments
module_args = dict( username = dict(required=True) )
# module instantiation
module = AnsibleModule( argument_spec = module_args, supports_check_mode=True,)
# module variables
username = module.params[’username']
# module execution
# do something
# if something fails:
# module.fail_json(msg=‘command failed’)
module_returns = {
"result":"my module’s result was blah",
"changed" : False,
"rc" : 4,
"ansible_facts" : {},
}
module.exit_json(**module_returns)
main()
copyright	
  2014.	
  all	
  rights	
  reserved.	
  
resources
•  Ansible	
  Role	
  Manager	
  
hNps://pypi.python.org/pypi/ansible-­‐role-­‐manager	
  
•  Django	
  Deploy	
  &	
  Release	
  Playbooks	
  
hNps://github.com/mirskytech-­‐ansible/playbook-­‐django	
  
•  Ansible	
  Tower	
  
•  Ansible	
  Galaxy	
  
•  Ansible	
  Docs	
  
hNp://docs.ansible.com/quickstart.html	
  
hNp://docs.ansible.com/playbooks_best_prac=ces.html	
  
hNp://docs.ansible.com/list_of_all_modules.html	
  
hNp://docs.ansible.com/	
  
•  MirskyTech	
  Blog	
  
hNp://mirskytech.com/overflow/	
  
•  Django	
  Pony	
  Logo	
  
hNp://doctormo.deviantart.com/art/Django-­‐Python-­‐Pony-­‐449031453	
  
	
  
contact info
questions?
andrew@mirskytech.com	
  
	
  

More Related Content

What's hot

What's hot (20)

Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)
 
Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)
 
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
 
Introducing Ansible
Introducing AnsibleIntroducing Ansible
Introducing Ansible
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Making environment for_infrastructure_as_code
Making environment for_infrastructure_as_codeMaking environment for_infrastructure_as_code
Making environment for_infrastructure_as_code
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Ansible - Crash course
Ansible - Crash courseAnsible - Crash course
Ansible - Crash course
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
 
How to manage Microsoft Azure with open source
How to manage Microsoft Azure with open sourceHow to manage Microsoft Azure with open source
How to manage Microsoft Azure with open source
 
Ansible fest Presentation slides
Ansible fest Presentation slidesAnsible fest Presentation slides
Ansible fest Presentation slides
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
Configuration Management in Ansible
Configuration Management in Ansible Configuration Management in Ansible
Configuration Management in Ansible
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2
 
Ansible, best practices
Ansible, best practicesAnsible, best practices
Ansible, best practices
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
 
Ansible101
Ansible101Ansible101
Ansible101
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changer
 

Viewers also liked

Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTT
kevinvw
 
PDXPortland - Dockerize Django
PDXPortland - Dockerize DjangoPDXPortland - Dockerize Django
PDXPortland - Dockerize Django
Hannes Hapke
 
How Emacs changed my life
How Emacs changed my lifeHow Emacs changed my life
How Emacs changed my life
yukihiro_matz
 
AWS Elastic Beanstalk and Docker
AWS Elastic Beanstalk and DockerAWS Elastic Beanstalk and Docker
AWS Elastic Beanstalk and Docker
Docker, Inc.
 

Viewers also liked (20)

How to write a well-behaved Python command line application
How to write a well-behaved Python command line applicationHow to write a well-behaved Python command line application
How to write a well-behaved Python command line application
 
Using Objects to Organize your jQuery Code
Using Objects to Organize your jQuery CodeUsing Objects to Organize your jQuery Code
Using Objects to Organize your jQuery Code
 
EmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image AnalysisEmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image Analysis
 
ORM in Django
ORM in DjangoORM in Django
ORM in Django
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTT
 
PDXPortland - Dockerize Django
PDXPortland - Dockerize DjangoPDXPortland - Dockerize Django
PDXPortland - Dockerize Django
 
Django via Docker
Django via DockerDjango via Docker
Django via Docker
 
Develop with docker 2014 aug
Develop with docker 2014 augDevelop with docker 2014 aug
Develop with docker 2014 aug
 
Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and code
 
GNU Parallel - Ole Tange
GNU Parallel - Ole TangeGNU Parallel - Ole Tange
GNU Parallel - Ole Tange
 
Django and Docker
Django and DockerDjango and Docker
Django and Docker
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Django
 
Spring Framework - Expression Language
Spring Framework - Expression LanguageSpring Framework - Expression Language
Spring Framework - Expression Language
 
How Emacs changed my life
How Emacs changed my lifeHow Emacs changed my life
How Emacs changed my life
 
Efficient Django
Efficient DjangoEfficient Django
Efficient Django
 
Pets vs. Cattle: The Elastic Cloud Story
Pets vs. Cattle: The Elastic Cloud StoryPets vs. Cattle: The Elastic Cloud Story
Pets vs. Cattle: The Elastic Cloud Story
 
OMA Lightweight M2M Tutorial
OMA Lightweight M2M TutorialOMA Lightweight M2M Tutorial
OMA Lightweight M2M Tutorial
 
Getting started with AWS IoT on Raspberry Pi
Getting started with AWS IoT on Raspberry PiGetting started with AWS IoT on Raspberry Pi
Getting started with AWS IoT on Raspberry Pi
 
Docker and Go: why did we decide to write Docker in Go?
Docker and Go: why did we decide to write Docker in Go?Docker and Go: why did we decide to write Docker in Go?
Docker and Go: why did we decide to write Docker in Go?
 
AWS Elastic Beanstalk and Docker
AWS Elastic Beanstalk and DockerAWS Elastic Beanstalk and Docker
AWS Elastic Beanstalk and Docker
 

Similar to Deploying Django with Ansible

Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
Omar Reygaert
 
Provisioning with Puppet
Provisioning with PuppetProvisioning with Puppet
Provisioning with Puppet
Joe Ray
 
From Dev to DevOps - Apache Barcamp Spain 2011
From Dev to DevOps - Apache Barcamp Spain 2011From Dev to DevOps - Apache Barcamp Spain 2011
From Dev to DevOps - Apache Barcamp Spain 2011
Carlos Sanchez
 
From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011
Carlos Sanchez
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
Carlos Sanchez
 

Similar to Deploying Django with Ansible (20)

Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansible
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
 
“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.
 
infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and Maintenance
 
Provisioning with Puppet
Provisioning with PuppetProvisioning with Puppet
Provisioning with Puppet
 
From Dev to DevOps
From Dev to DevOpsFrom Dev to DevOps
From Dev to DevOps
 
Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
From Dev to DevOps - Apache Barcamp Spain 2011
From Dev to DevOps - Apache Barcamp Spain 2011From Dev to DevOps - Apache Barcamp Spain 2011
From Dev to DevOps - Apache Barcamp Spain 2011
 
From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
 
Software Defined Datacenter
Software Defined DatacenterSoftware Defined Datacenter
Software Defined Datacenter
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloud
 
Dev ops
Dev opsDev ops
Dev ops
 
Ansible new paradigms for orchestration
Ansible new paradigms for orchestrationAnsible new paradigms for orchestration
Ansible new paradigms for orchestration
 
One-Man Ops
One-Man OpsOne-Man Ops
One-Man Ops
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Deploying Django with Ansible

  • 1. copyright  2014.  all  rights  reserved.   Deploying Django with Ansible Andrew  Mirsky  
  • 2. copyright  2014.  all  rights  reserved.   For  development:   ~/myproject > ./manage.py runserver Validating models... 0 errors found May 30, 2014 - 11:31:08 Django version 1.6.2, using settings 'settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.   For  produc0on:   /var/www > sudo ./manage.py runserver 0.0.0.0:80 /dev/null 2>&1 & /var/www >   running a django server
  • 3. copyright  2014.  all  rights  reserved.   production setup •  One  or  more  applica=ons  (aka  virtual  servers)   •  Mul=ple  applica=on  processes  &  monitoring   •  Data  storage  &  retrieval  (aka  databases)   •  Security   •  Maintainable,  robust,  scalable  
  • 4. copyright  2014.  all  rights  reserved.   basic setup
  • 5. copyright  2014.  all  rights  reserved.   components •  webservers   –  apache   –  nginx   –  cherokee   •  interpreter   –  mod_wsgi   –  uwsgi   –  gunicorn   •  databases   –  postgres   –  mysql   –  [  mongodb,  couchdb,  cassandra  ]  
  • 6. copyright  2014.  all  rights  reserved.   scalable setup
  • 7. copyright  2014.  all  rights  reserved.   scalable, redundant setup
  • 8. copyright  2014.  all  rights  reserved.   ansible
  • 9. copyright  2014.  all  rights  reserved.   ansible for single commands > pip install ansible > ansible webservers –i myinventory -a ”touch /srv/foo.txt && /sbin/reboot" -f 10
  • 10. copyright  2014.  all  rights  reserved.   anatomy of an inventory > cat inventory # file: inventory [webservers] app[0:4].mirsky.net ansible_ssh_private_key_file=~/.ssh/key1.pem [dbservers] db[0:2].mirsky.net ansible_ssh_private_key_file=~/.ssh/key2.pem [mytotalsite:children] webserver dbservers
  • 11. copyright  2014.  all  rights  reserved.   ansible playbooks
  • 12. copyright  2014.  all  rights  reserved.   building playbooks > pip install ansible-role-manager > arm help usage: /Users/andrew/env/arm/bin/arm [-h] {freeze,help,init,install,uninstall} ... positional arguments: {freeze,help,init,install,uninstall} freeze produces dependencies file for this playbook based on... help an alias for calling `-h` on any subcommand init initialize directory structure & files install install playbook role uninstall remove a role from the library of dependencies > arm init -p mydjangoplaybook ansible playbook created successfully > arm install git+https://github.com/mirskytech-ansible/role-postgres.git
  • 13. copyright  2014.  all  rights  reserved.   anatomy of a playbook > cat mydjangoplaybook/mysite.yml  ## file: mysite.yml !!   !! ## usage: ansible-playbook -i <inventory file> mysite.yml !! - hosts: webservers vars: webservers   - project: mydjangoproject     roles:       - cherokee       - postgres   tasks:     - name: install uwsgi & postgres modules     sudo: yes     pip: name="uwsgi psycopg2”
  • 14. copyright  2014.  all  rights  reserved.   anatomy of a role > cat roles/cherokee/tasks/main.yml --- ## file: cherokee/tasks/main.yml  - name: add cherokee ppa    sudo: yes    command: mkdir /srv/www && chgrp www-data /srv/www  - name: add cherokee ppa    sudo: yes    apt_repository: repo="ppa:cherokee-webserver" state="present"    register: ppa_add    ignore_errors: true     - name: package install     sudo: yes     apt: pkg={{ item }} state=present update_cache=yes     with_items:       - cherokee       - libcherokee-mod-libssl     register: apt_install     ignore_errors: true     when: ppa_add|success
  • 15. copyright  2014.  all  rights  reserved.   anatomy of a task   - name: create uwsgi config file     sudo: yes     template: >         src=templates/uwsgi.ini.j2         dest=/srv/www/{{ project }}/uwsgi.ini         group='www-data'         mode=660 register: this_task_rc     ignore_errors: true     when: previous_task_rc|success > cat templates/uwsgi.ini.j2 # uwsgi.ini for {{ hostname }}   [uwsgi] vhost = true master = true enable-threads = true processes = 2 wsgi-file = /srv/www/{{ project }}/webapp/wsgi.py virtualenv = /srv/env/{{ project }} chdir = /srv/www/{{ project }} touch-reload = /srv/reload/{{ project }} pythonpath = /srv/www/{{ project }} daemonize = /var/log/{{ hostname }}.log post-buffering = 32768 Ansible’s  Template  Module  Docs  
  • 16. copyright  2014.  all  rights  reserved.   anatomy of a module > cat library/mymodule_command from ansible.module_utils.basic import * def main(): # module arguments module_args = dict( username = dict(required=True) ) # module instantiation module = AnsibleModule( argument_spec = module_args, supports_check_mode=True,) # module variables username = module.params[’username'] # module execution # do something # if something fails: # module.fail_json(msg=‘command failed’) module_returns = { "result":"my module’s result was blah", "changed" : False, "rc" : 4, "ansible_facts" : {}, } module.exit_json(**module_returns) main()
  • 17. copyright  2014.  all  rights  reserved.   resources •  Ansible  Role  Manager   hNps://pypi.python.org/pypi/ansible-­‐role-­‐manager   •  Django  Deploy  &  Release  Playbooks   hNps://github.com/mirskytech-­‐ansible/playbook-­‐django   •  Ansible  Tower   •  Ansible  Galaxy   •  Ansible  Docs   hNp://docs.ansible.com/quickstart.html   hNp://docs.ansible.com/playbooks_best_prac=ces.html   hNp://docs.ansible.com/list_of_all_modules.html   hNp://docs.ansible.com/   •  MirskyTech  Blog   hNp://mirskytech.com/overflow/   •  Django  Pony  Logo   hNp://doctormo.deviantart.com/art/Django-­‐Python-­‐Pony-­‐449031453     contact info questions? andrew@mirskytech.com