Skip to content

Commit ed13789

Browse files
author
Sergey Stankevich
committed
Initial import
0 parents  commit ed13789

17 files changed

+601
-0
lines changed

LICENSE.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright © 2012 Sergey Stankevich
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
    [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

Modulefile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name 'puppet-python'
2+
version '1.0.0'
3+
4+
author 'Sergey Stankevich'
5+
license 'Apache License, Version 2.0'
6+
project_page 'https://github.com/stankevich/puppet-python'
7+
source 'git://github.com/stankevich/puppet-python'
8+
summary 'Puppet module for Python'
9+
description 'Installs and manages Python, pip, virtualenv, Gunicorn virtual hosts.'

README.md

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
[puppet-python](https://github.com/stankevich/puppet-python)
2+
======
3+
4+
Puppet module for installing and managing python, pip, virtualenv, Gunicorn virtual hosts
5+
6+
## Usage
7+
8+
### python
9+
10+
Installs and manages python, python-dev, python-virtualenv and Gunicorn.
11+
12+
**version** — Python version to install. Default: system default
13+
14+
**dev** — Install python-dev. Default: false
15+
16+
**virtualenv** — Install python-virtualenv. Default: false
17+
18+
**gunicorn** — Install Gunicorn. Default: false
19+
20+
class { 'python':
21+
version => 'system',
22+
dev => true,
23+
virtualenv => true,
24+
gunicorn => true,
25+
}
26+
27+
### python::pip
28+
29+
Installs and manages packages from pip.
30+
31+
**ensure** — present/absent. Default: present
32+
33+
**virtualenv** — virtualenv to run pip in.
34+
35+
**proxy** — Proxy server to use for outbound connections. Default: none
36+
37+
python::pip { 'flask':
38+
virtualenv => '/var/www/project1',
39+
proxy => 'http://proxy.domain.com:3128',
40+
}
41+
42+
### python::requirements
43+
44+
Installs and manages Python packages from requirements file.
45+
46+
**virtualenv** — virtualenv to run pip in. Default: system-wide
47+
48+
**proxy** — Proxy server to use for outbound connections. Default: none
49+
50+
python::requirements { '/var/www/project1/requirements.txt':
51+
virtualenv => '/var/www/project1',
52+
proxy => 'http://proxy.domain.com:3128',
53+
}
54+
55+
### python::virtualenv
56+
57+
Creates Python virtualenv.
58+
59+
**ensure** — present/absent. Default: present
60+
61+
**version** — Python version to use. Default: system default
62+
63+
**requirements** — Path to pip requirements.txt file. Default: none
64+
65+
**proxy** — Proxy server to use for outbound connections. Default: none
66+
67+
python::virtualenv { '/var/www/project1':
68+
ensure => present,
69+
version => 'system',
70+
requirements => '/var/www/project1/requirements.txt',
71+
proxy => 'http://proxy.domain.com:3128',
72+
}
73+
74+
### python::gunicorn
75+
76+
Manages Gunicorn virtual hosts.
77+
78+
**ensure** — present/absent. Default: present
79+
80+
**virtualenv** — Run in virtualenv, specify directory. Default: disabled
81+
82+
**mode** — Gunicorn mode. wsgi/django. Default: wsgi
83+
84+
**dir** — Application directory.
85+
86+
**bind** — Bind on: 'HOST', 'HOST:PORT', 'unix:PATH'. Default: unix:/tmp/gunicorn-$name.socket or unix:${virtualenv}/${name}.socket
87+
88+
**environment** — Set ENVIRONMENT variable. Default: none
89+
90+
python::gunicorn { 'vhost':
91+
ensure => present,
92+
virtualenv => '/var/www/project1',
93+
mode => 'wsgi',
94+
dir => '/var/www/project1/current',
95+
bind => 'unix:/tmp/gunicorn.socket',
96+
environment => 'prod',
97+
}
98+
99+
## Authors
100+
101+
[Sergey Stankevich](https://github.com/stankevich)

Rakefile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Rakefile for puppet-lint (https://github.com/rodjek/puppet-lint)
2+
# Run: rake lint
3+
4+
require 'puppet-lint/tasks/puppet-lint'
5+
PuppetLint.configuration.with_filename = true
6+
PuppetLint.configuration.send('disable_documentation')
7+
PuppetLint.configuration.send('disable_class_parameter_defaults')
8+
PuppetLint.configuration.send('disable_80chars')

manifests/config.pp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class python::config {
2+
3+
Class['python::install'] -> Python::Pip <| |>
4+
Class['python::install'] -> Python::Requirements <| |>
5+
Class['python::install'] -> Python::Virtualenv <| |>
6+
7+
Python::Virtualenv <| |> -> Python::Pip <| |>
8+
Python::Virtualenv <| |> -> Python::Requirements <| |>
9+
10+
if $python::gunicorn {
11+
Class['python::install'] -> Python::Gunicorn <| |>
12+
13+
Python::Gunicorn <| |> ~> Service['gunicorn']
14+
15+
service { 'gunicorn':
16+
ensure => running,
17+
enable => true,
18+
hasrestart => true,
19+
hasstatus => false,
20+
pattern => '/usr/bin/gunicorn',
21+
}
22+
}
23+
24+
}

manifests/gunicorn.pp

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# == Define: python::gunicorn
2+
#
3+
# Manages Gunicorn virtual hosts.
4+
#
5+
# === Parameters
6+
#
7+
# [*ensure*]
8+
# present|absent. Default: present
9+
#
10+
# [*virtualenv*]
11+
# Run in virtualenv, specify directory. Default: disabled
12+
#
13+
# [*mode*]
14+
# Gunicorn mode.
15+
# wsgi|django. Default: wsgi
16+
#
17+
# [*dir*]
18+
# Application directory.
19+
#
20+
# [*bind*]
21+
# Bind on: 'HOST', 'HOST:PORT', 'unix:PATH'.
22+
# Default: system-wide: unix:/tmp/gunicorn-$name.socket
23+
# virtualenv: unix:${virtualenv}/${name}.socket
24+
#
25+
# [*environment*]
26+
# Set ENVIRONMENT variable. Default: none
27+
#
28+
# === Examples
29+
#
30+
# python::gunicorn { 'vhost':
31+
# ensure => present,
32+
# virtualenv => '/var/www/project1',
33+
# mode => 'wsgi',
34+
# dir => '/var/www/project1/current',
35+
# bind => 'unix:/tmp/gunicorn.socket',
36+
# environment => 'prod',
37+
# }
38+
#
39+
# === Authors
40+
#
41+
# Sergey Stankevich
42+
#
43+
define python::gunicorn (
44+
$ensure = present,
45+
$virtualenv = false,
46+
$mode = 'wsgi',
47+
$dir = false,
48+
$bind = false,
49+
$environment = false
50+
) {
51+
52+
# Parameter validation
53+
if ! $dir {
54+
fail('python::gunicorn: dir parameter must not be empty')
55+
}
56+
57+
file { "/etc/gunicorn.d/${name}":
58+
ensure => $ensure,
59+
mode => '0644',
60+
owner => 'root',
61+
group => 'root',
62+
content => template('python/gunicorn.erb'),
63+
}
64+
65+
}

manifests/init.pp

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# == Class: python
2+
#
3+
# Installs and manages python, python-dev, python-virtualenv and Gunicorn.
4+
#
5+
# === Parameters
6+
#
7+
# [*version*]
8+
# Python version to install. Default: system default
9+
#
10+
# [*dev*]
11+
# Install python-dev. Default: false
12+
#
13+
# [*virtualenv*]
14+
# Install python-virtualenv. Default: false
15+
#
16+
# [*gunicorn*]
17+
# Install Gunicorn. Default: false
18+
#
19+
# === Examples
20+
#
21+
# class { 'python':
22+
# version => 'system',
23+
# dev => true,
24+
# virtualenv => true,
25+
# gunicorn => true,
26+
# }
27+
#
28+
# === Authors
29+
#
30+
# Sergey Stankevich
31+
#
32+
class python (
33+
$version = 'system',
34+
$dev = false,
35+
$virtualenv = false,
36+
$gunicorn = false
37+
) {
38+
39+
# Module compatibility check
40+
$compatible = [ 'Debian', 'Ubuntu' ]
41+
if ! ($::operatingsystem in $compatible) {
42+
fail("Module is not compatible with ${::operatingsystem}")
43+
}
44+
45+
Class['python::install'] -> Class['python::config']
46+
47+
include python::install
48+
include python::config
49+
50+
}

manifests/install.pp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class python::install {
2+
3+
$python = $python::version ? {
4+
'system' => 'python',
5+
default => "python${python::version}",
6+
}
7+
8+
package { $python: ensure => present }
9+
10+
$dev_ensure = $python::dev ? {
11+
true => present,
12+
default => absent,
13+
}
14+
15+
package { "${python}-dev": ensure => $dev_ensure }
16+
17+
$venv_ensure = $python::virtualenv ? {
18+
true => present,
19+
default => absent,
20+
}
21+
22+
package { 'python-virtualenv': ensure => $venv_ensure }
23+
24+
$gunicorn_ensure = $python::gunicorn ? {
25+
true => present,
26+
default => absent,
27+
}
28+
29+
package { 'gunicorn': ensure => $gunicorn_ensure }
30+
31+
}

manifests/pip.pp

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# == Define: python::pip
2+
#
3+
# Installs and manages packages from pip.
4+
#
5+
# === Parameters
6+
#
7+
# [*ensure*]
8+
# present|absent. Default: present
9+
#
10+
# [*virtualenv*]
11+
# virtualenv to run pip in.
12+
#
13+
# [*proxy*]
14+
# Proxy server to use for outbound connections. Default: none
15+
#
16+
# === Examples
17+
#
18+
# python::pip { 'flask':
19+
# virtualenv => '/var/www/project1',
20+
# proxy => 'http://proxy.domain.com:3128',
21+
# }
22+
#
23+
# === Authors
24+
#
25+
# Sergey Stankevich
26+
#
27+
define python::pip (
28+
$virtualenv,
29+
$ensure = present,
30+
$proxy = false
31+
) {
32+
33+
# Parameter validation
34+
if ! $virtualenv {
35+
fail('python::pip: virtualenv parameter must not be empty')
36+
}
37+
38+
$proxy_flag = $proxy ? {
39+
false => '',
40+
default => "--proxy=${proxy}",
41+
}
42+
43+
$grep_regex = $name ? {
44+
/==/ => "^${name}\$",
45+
default => "^${name}==",
46+
}
47+
48+
case $ensure {
49+
present: {
50+
exec { "pip_install_${name}":
51+
command => "${virtualenv}/bin/pip install ${proxy_flag} ${name}",
52+
unless => "${virtualenv}/bin/pip freeze | grep -i -e ${grep_regex}",
53+
}
54+
}
55+
56+
default: {
57+
exec { "pip_uninstall_${name}":
58+
command => "echo y | ${virtualenv}/bin/pip uninstall ${proxy_flag} ${name}",
59+
onlyif => "${virtualenv}/bin/pip freeze | grep -i -e ${grep_regex}",
60+
}
61+
}
62+
}
63+
64+
}

0 commit comments

Comments
 (0)