Skip to content

Commit 5d26f95

Browse files
committed
Merge pull request voxpupuli#20 from fgimian/master
Stability & performance improvements along with a few new features (take what you wish)
2 parents 9aae0a0 + 07e6cc6 commit 5d26f95

7 files changed

Lines changed: 165 additions & 68 deletions

File tree

Modulefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name 'puppet-python'
2-
version '1.0.0'
2+
version '1.1.4'
33

4-
author 'Sergey Stankevich'
4+
author 'Fotis Gimian'
55
license 'Apache License, Version 2.0'
6-
project_page 'https://github.com/stankevich/puppet-python'
7-
source 'git://github.com/stankevich/puppet-python'
6+
project_page 'https://github.com/fgimian/puppet-python'
7+
source 'git://github.com/fgimian/puppet-python'
88
summary 'Puppet module for Python'
99
description 'Installs and manages Python, pip, virtualenv, Gunicorn virtual hosts.'

README.md

Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
1-
[puppet-python](https://github.com/stankevich/puppet-python)
1+
[puppet-python](https://github.com/fgimian/puppet-python)
22
======
33

4-
Puppet module for installing and managing python, pip, virtualenvs and Gunicorn virtual hosts.
4+
This project was forked from [stankevich's Github page](https://github.com/stankevich/puppet-python)
5+
6+
Puppet module for installing and managing python, pip, virtualenvs and Gunicorn virtual hosts. This fork makes several fundamental changes to the core of this module, adding some additional features, improving performance and making operations more robust in general.
7+
8+
**Version 1.1.x Notes (fgimian fork)**
9+
10+
Version 1.1.x makes several fundamental changes to the core of this module, adding some additional features, improving performance and making operations more robust in general.
11+
12+
Please note that everal changes have been made in v1.1.x which make manifests incompatible with the previous version. However, modifying your manifests to suit is trivial. Please see the notes below.
13+
14+
Currently, the changes you need to make are as follows:
15+
16+
* All pip definitions MUST include the owner field which specifies which user owns the virtualenv that packages will be installed in. Adding this greatly improves performance and efficiency of this module.
17+
* You must explicitly specify pip => true in the python class if you want pip installed. As such, the pip package is now independent of the dev package and so one can exist without the other.
18+
19+
## Installation
20+
21+
``` bash
22+
cd /etc/puppet/modules
23+
git clone git://github.com/fgimian/puppet-python.git python
24+
```
525

626
## Usage
727

828
### python
929

1030
Installs and manages python, python-dev, python-virtualenv and Gunicorn.
1131

12-
**version** Python version to install. Default: system default
32+
**version** - Python version to install. Default: system default
1333

14-
**dev** Install python-dev. Default: false
34+
**pip** - Install python-pip. Default: false
1535

16-
**virtualenv** Install python-virtualenv. Default: false
36+
**dev** - Install python-dev. Default: false
1737

18-
**gunicorn** — Install Gunicorn. Default: false
38+
**virtualenv** - Install python-virtualenv. Default: false
39+
40+
**gunicorn** - Install Gunicorn. Default: false
1941

2042
class { 'python':
2143
version => 'system',
@@ -28,52 +50,65 @@ Installs and manages python, python-dev, python-virtualenv and Gunicorn.
2850

2951
Installs and manages packages from pip.
3052

31-
**ensure** present/absent. Default: present
53+
**ensure** - present/absent. Default: present
3254

33-
**virtualenv** virtualenv to run pip in.
55+
**virtualenv** - virtualenv to run pip in. Default: system (no virtualenv)
3456

35-
**url** URL to install from. Default: none
57+
**url** - URL to install from. Default: none
3658

37-
**proxy** — Proxy server to use for outbound connections. Default: none
59+
**owner** - The owner of the virtualenv to ensure that packages are installed with the correct permissions (must be specified). Default: root
3860

39-
python::pip { 'flask':
40-
virtualenv => '/var/www/project1',
41-
proxy => 'http://proxy.domain.com:3128',
61+
**proxy** - Proxy server to use for outbound connections. Default: none
62+
63+
**environment** - Additional environment variables required to install the packages. Default: none
64+
65+
python::pip { 'cx_Oracle':
66+
virtualenv => '/var/www/project1',
67+
owner => 'appuser',
68+
proxy => 'http://proxy.domain.com:3128',
69+
environment => 'ORACLE_HOME=/usr/lib/oracle/11.2/client64',
4270
}
4371

4472
### python::requirements
4573

4674
Installs and manages Python packages from requirements file.
4775

48-
**virtualenv** — virtualenv to run pip in. Default: system-wide
76+
**virtualenv** - virtualenv to run pip in. Default: system-wide
77+
78+
**proxy** - Proxy server to use for outbound connections. Default: none
79+
80+
**owner** - The owner of the virtualenv to ensure that packages are installed with the correct permissions (must be specified). Default: root
4981

50-
**proxy** — Proxy server to use for outbound connections. Default: none
82+
**group** - The group that was used to create the virtualenv. This is used to create the requirements file with correct permissions if it's not present already.
5183

5284
python::requirements { '/var/www/project1/requirements.txt':
5385
virtualenv => '/var/www/project1',
5486
proxy => 'http://proxy.domain.com:3128',
87+
owner => 'appuser',
88+
group => 'apps',
5589
}
5690

5791
### python::virtualenv
5892

5993
Creates Python virtualenv.
6094

61-
**ensure** present/absent. Default: present
95+
**ensure** - present/absent. Default: present
6296

63-
**version** Python version to use. Default: system default
97+
**version** - Python version to use. Default: system default
6498

65-
**requirements** Path to pip requirements.txt file. Default: none
99+
**requirements** - Path to pip requirements.txt file. Default: none
66100

67-
**proxy** Proxy server to use for outbound connections. Default: none
101+
**proxy** - Proxy server to use for outbound connections. Default: none
68102

69-
**systempkgs** Copy system site-packages into virtualenv. Default: don't
103+
**systempkgs** - Copy system site-packages into virtualenv. Default: don't
70104

71-
**distribute** Include distribute in the virtualenv. Default: true
105+
**distribute** - Include distribute in the virtualenv. Default: true
72106

73-
** owner ** - specify the owner of this virtualenv
107+
**owner** - Specify the owner of this virtualenv
74108

75-
** group ** - specify the group for this virtualenv
109+
**group** - Specify the group for this virtualenv
76110

111+
**index** - Base URL of Python package index. Default: none
77112

78113
python::virtualenv { '/var/www/project1':
79114
ensure => present,
@@ -90,19 +125,19 @@ Creates Python virtualenv.
90125

91126
Manages Gunicorn virtual hosts.
92127

93-
**ensure** present/absent. Default: present
128+
**ensure** - present/absent. Default: present
94129

95-
**virtualenv** Run in virtualenv, specify directory. Default: disabled
130+
**virtualenv** - Run in virtualenv, specify directory. Default: disabled
96131

97-
**mode** Gunicorn mode. wsgi/django. Default: wsgi
132+
**mode** - Gunicorn mode. wsgi/django. Default: wsgi
98133

99-
**dir** Application directory.
134+
**dir** - Application directory.
100135

101-
**bind** Bind on: 'HOST', 'HOST:PORT', 'unix:PATH'. Default: unix:/tmp/gunicorn-$name.socket or unix:${virtualenv}/${name}.socket
136+
**bind** - Bind on: 'HOST', 'HOST:PORT', 'unix:PATH'. Default: unix:/tmp/gunicorn-$name.socket or unix:${virtualenv}/${name}.socket
102137

103-
**environment** Set ENVIRONMENT variable. Default: none
138+
**environment** - Set ENVIRONMENT variable. Default: none
104139

105-
**template** Which ERB template to use. Default: python/gunicorn.erb
140+
**template** - Which ERB template to use. Default: python/gunicorn.erb
106141

107142
python::gunicorn { 'vhost':
108143
ensure => present,
@@ -119,3 +154,4 @@ Manages Gunicorn virtual hosts.
119154
[Sergey Stankevich](https://github.com/stankevich)
120155
[Ashley Penney](https://github.com/apenney)
121156
[Marc Fournier](https://github.com/mfournier)
157+
[Fotis Gimian](https://github.com/fgimian)

manifests/init.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
# [*version*]
88
# Python version to install. Default: system default
99
#
10+
# [*pip*]
11+
# Install python-pip. Default: false
12+
#
1013
# [*dev*]
1114
# Install python-dev. Default: false
1215
#
@@ -20,6 +23,7 @@
2023
#
2124
# class { 'python':
2225
# version => 'system',
26+
# pip => true,
2327
# dev => true,
2428
# virtualenv => true,
2529
# gunicorn => true,
@@ -31,6 +35,7 @@
3135
#
3236
class python (
3337
$version = 'system',
38+
$pip = false,
3439
$dev = false,
3540
$virtualenv = false,
3641
$gunicorn = false

manifests/install.pp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
}
77

88
$pythondev = $::operatingsystem ? {
9-
/(?i:RedHat|CentOS|Fedora)/ => "$python-devel",
10-
/(?i:Debian|Ubuntu)/ => "$python-dev"
9+
/(?i:RedHat|CentOS|Fedora)/ => "${python}-devel",
10+
/(?i:Debian|Ubuntu)/ => "${python}-dev"
1111
}
1212

1313
package { $python: ensure => present }
@@ -17,7 +17,13 @@
1717
default => absent,
1818
}
1919

20-
package { [ $pythondev, 'python-pip' ]: ensure => $dev_ensure }
20+
$pip_ensure = $python::pip ? {
21+
true => present,
22+
default => absent,
23+
}
24+
25+
package { $pythondev: ensure => $dev_ensure }
26+
package { 'python-pip': ensure => $pip_ensure }
2127

2228
$venv_ensure = $python::virtualenv ? {
2329
true => present,

manifests/pip.pp

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313
# [*url*]
1414
# URL to install from. Default: none
1515
#
16+
# [*owner*]
17+
# The owner of the virtualenv being manipulated. Default: root
18+
#
1619
# [*proxy*]
1720
# Proxy server to use for outbound connections. Default: none
1821
#
22+
# [*environment*]
23+
# Additional environment variables required to install the packages. Default: none
24+
#
1925
# === Examples
2026
#
2127
# python::pip { 'flask':
@@ -26,19 +32,36 @@
2632
# === Authors
2733
#
2834
# Sergey Stankevich
35+
# Fotis Gimian
2936
#
3037
define python::pip (
31-
$virtualenv,
32-
$ensure = present,
33-
$url = false,
34-
$proxy = false
38+
$ensure = present,
39+
$virtualenv = 'system',
40+
$url = false,
41+
$owner = 'root',
42+
$proxy = false,
43+
$environment = []
3544
) {
3645

3746
# Parameter validation
3847
if ! $virtualenv {
3948
fail('python::pip: virtualenv parameter must not be empty')
4049
}
4150

51+
if $virtualenv == 'system' and $owner != 'root' {
52+
fail('python::pip: root user must be used when virtualenv is system')
53+
}
54+
55+
$cwd = $virtualenv ? {
56+
'system' => '/',
57+
default => "${virtualenv}",
58+
}
59+
60+
$pip_env = $virtualenv ? {
61+
'system' => 'pip',
62+
default => "${virtualenv}/bin/pip",
63+
}
64+
4265
$proxy_flag = $proxy ? {
4366
false => '',
4467
default => "--proxy=${proxy}",
@@ -57,15 +80,19 @@
5780
case $ensure {
5881
present: {
5982
exec { "pip_install_${name}":
60-
command => "${virtualenv}/bin/pip install ${proxy_flag} ${source}",
61-
unless => "${virtualenv}/bin/pip freeze | grep -i -e ${grep_regex}",
83+
command => "$pip_env --log-file ${cwd}/pip.log install ${proxy_flag} ${source}",
84+
unless => "$pip_env freeze | grep -i -e ${grep_regex}",
85+
user => $owner,
86+
environment => $environment,
6287
}
6388
}
6489

6590
default: {
6691
exec { "pip_uninstall_${name}":
67-
command => "echo y | ${virtualenv}/bin/pip uninstall ${proxy_flag} ${name}",
68-
onlyif => "${virtualenv}/bin/pip freeze | grep -i -e ${grep_regex}",
92+
command => "echo y | $pip_env uninstall ${proxy_flag} ${name}",
93+
onlyif => "$pip_env freeze | grep -i -e ${grep_regex}",
94+
user => $owner,
95+
environment => $environment,
6996
}
7097
}
7198
}

manifests/requirements.pp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@
1010
# [*virtualenv*]
1111
# virtualenv to run pip in. Default: system-wide
1212
#
13+
# [*owner*]
14+
# The owner of the virtualenv being manipulated. Default: root
15+
#
16+
# [*group*]
17+
# The group relating to the virtualenv being manipulated. Default: root
18+
#
1319
# [*proxy*]
1420
# Proxy server to use for outbound connections. Default: none
1521
#
22+
# [*environment*]
23+
# Additional environment variables required to install the packages. Default: none
24+
#
1625
# === Examples
1726
#
1827
# python::requirements { '/var/www/project1/requirements.txt':
@@ -24,22 +33,28 @@
2433
#
2534
# Sergey Stankevich
2635
# Ashley Penney
36+
# Fotis Gimian
2737
#
2838
define python::requirements (
2939
$requirements = $name,
3040
$virtualenv = 'system',
31-
$proxy = false,
3241
$owner = 'root',
33-
$group = 'root'
42+
$group = 'root',
43+
$proxy = false,
44+
$environment = []
3445
) {
3546

47+
if $virtualenv == 'system' and ($owner != 'root' or $group != 'root') {
48+
fail('python::pip: root user must be used when virtualenv is system')
49+
}
50+
3651
$cwd = $virtualenv ? {
3752
'system' => '/',
38-
default => "${virtualenv}/bin/",
53+
default => "${virtualenv}",
3954
}
4055

4156
$pip_env = $virtualenv ? {
42-
'system' => '`which pip`',
57+
'system' => 'pip',
4358
default => "${virtualenv}/bin/pip",
4459
}
4560

@@ -64,12 +79,12 @@
6479

6580
exec { "python_requirements${name}":
6681
provider => shell,
67-
command => "${pip_env} install ${proxy_flag} -r ${requirements}",
68-
cwd => $cwd,
82+
command => "${pip_env} --log-file ${cwd}/pip.log install ${proxy_flag} -r ${requirements}",
6983
refreshonly => true,
7084
timeout => 1800,
7185
user => $owner,
7286
subscribe => File[$requirements],
87+
environment => $environment,
7388
}
7489

7590
}

0 commit comments

Comments
 (0)