public
Last active

Deploying Django with Puppet

  • Download Gist
deps.pp
Puppet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
stage { "pre": before => Stage["main"] }
class python {
package {
"build-essential": ensure => latest;
"python": ensure => "2.6.6-2ubuntu1";
"python-dev": ensure => "2.6.6-2ubuntu1";
"python-setuptools": ensure => "latest";
}
exec { "easy_install pip":
path => "/usr/local/bin:/usr/bin:/bin",
refreshonly => true,
require => Package["python-setuptools"],
subscribe => Package["python-setuptools"],
}
}
class { "python": stage => "pre" }
 
package {
"django":
ensure => "1.2.3",
provider => pip;
"libmysqlclient-dev":
ensure => "5.1.49-1ubuntu8.1";
"mysql-python":
ensure => "1.2.3",
provider => pip,
require => Package["libmysqlclient-dev"];
}
 
package { "fabric":
ensure => "0.9.3",
provider => pip,
}
 
package { "south":
ensure => "0.7.2",
provider => pip,
}
 
package {
"apache2-mpm-worker":
ensure => "2.2.16-1ubuntu3";
"libapache2-mod-wsgi":
ensure => "3.2-2";
}
 
file {
"/etc/apache2/sites-available/mysite":
content => template("mysite.erb"),
ensure => file,
require => Package["apache2-mpm-worker"];
"/etc/apache2/sites-enabled/001-mysite":
ensure => "/etc/apache2/sites-available/mysite",
require => Package["apache2-mpm-worker"];
"/etc/apache2/sites-enabled/000-default":
ensure => absent,
require => Package["apache2-mpm-worker"];
"/usr/local/share/wsgi/mysite/mysite.wsgi":
content => template("mysite.wsgi.erb"),
ensure => file;
}
 
service { "apache2":
enable => true,
ensure => running,
require => Package["apache2-mpm-worker"],
subscribe => [
Package[
"apache2-mpm-worker",
"libapache2-mod-wsgi"],
File[
"/etc/apache2/sites-available/mysite",
"/etc/apache2/sites-enabled/001-mysite",
"/etc/apache2/sites-enabled/000-default",
"/usr/local/share/wsgi/mysite/mysite.wsgi"]],
}
mysite.erb
HTML+ERB
1 2 3 4 5 6 7
<VirtualHost *:80>
DocumentRoot /usr/local/share/wsgi/mysite/media
Alias /media /usr/local/share/wsgi/mysite/media
WSGIScriptAlias / /usr/local/share/wsgi/mysite/mysite.wsgi
WSGIDaemonProcess mysite processes=<%= processorcount %>
WSGIProcessGroup mysite
</VirtualHost>
mysite.wsgi
Python
1 2 3 4 5 6 7 8
import os
import sys.path
 
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
sys.path.append('/usr/local/share/wsgi')
 
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.