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

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)Chu-Siang Lai
 
Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Soshi Nemoto
 
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017Jumping Bean
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationJohn Lynch
 
Making environment for_infrastructure_as_code
Making environment for_infrastructure_as_codeMaking environment for_infrastructure_as_code
Making environment for_infrastructure_as_codeSoshi Nemoto
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationKumar Y
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with AnsibleRayed Alrashed
 
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 sourceTaehee Jang
 
Ansible fest Presentation slides
Ansible fest Presentation slidesAnsible fest Presentation slides
Ansible fest Presentation slidesAaron Carey
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansiblebcoca
 
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 EC2Brian Schott
 
Ansible, best practices
Ansible, best practicesAnsible, best practices
Ansible, best practicesBas Meijer
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansibleOmid Vahdaty
 
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 + ec2Yros
 
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 changerSandro Paganotti
 

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

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 applicationgjcross
 
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 CodeRebecca Murphey
 
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 Analysisjeresig
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTTkevinvw
 
PDXPortland - Dockerize Django
PDXPortland - Dockerize DjangoPDXPortland - Dockerize Django
PDXPortland - Dockerize DjangoHannes Hapke
 
Develop with docker 2014 aug
Develop with docker 2014 augDevelop with docker 2014 aug
Develop with docker 2014 augVincent De Smet
 
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 codeDanielle Madeley
 
GNU Parallel - Ole Tange
GNU Parallel - Ole TangeGNU Parallel - Ole Tange
GNU Parallel - Ole TangeFSCONS
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Djangoryates
 
Spring Framework - Expression Language
Spring Framework - Expression LanguageSpring Framework - Expression Language
Spring Framework - Expression LanguageDzmitry Naskou
 
How Emacs changed my life
How Emacs changed my lifeHow Emacs changed my life
How Emacs changed my lifeyukihiro_matz
 
Efficient Django
Efficient DjangoEfficient Django
Efficient DjangoDavid Arcos
 
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 StoryRandy Bias
 
OMA Lightweight M2M Tutorial
OMA Lightweight M2M TutorialOMA Lightweight M2M Tutorial
OMA Lightweight M2M Tutorialzdshelby
 
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 PiIan Massingham
 
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?Jérôme Petazzoni
 
AWS Elastic Beanstalk and Docker
AWS Elastic Beanstalk and DockerAWS Elastic Beanstalk and Docker
AWS Elastic Beanstalk and DockerDocker, 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

Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansibleahamilton55
 
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 + PuppetOmar Reygaert
 
“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.Graham Dumpleton
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and MaintenanceJazkarta, Inc.
 
Provisioning with Puppet
Provisioning with PuppetProvisioning with Puppet
Provisioning with PuppetJoe Ray
 
From Dev to DevOps
From Dev to DevOpsFrom Dev to DevOps
From Dev to DevOpsAgile Spain
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleStein Inge Morisbak
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleStein Inge Morisbak
 
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 2011Carlos 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 2011Carlos Sanchez
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013grim_radical
 
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 2012Carlos Sanchez
 
Software Defined Datacenter
Software Defined DatacenterSoftware Defined Datacenter
Software Defined DatacenterNETWAYS
 
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 CloudWesley Beary
 
Ansible new paradigms for orchestration
Ansible new paradigms for orchestrationAnsible new paradigms for orchestration
Ansible new paradigms for orchestrationPaolo Tonin
 
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 BeyondDrupalDay
 

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

Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

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