summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Modulefile4
-rw-r--r--README.md25
-rw-r--r--manifests/init.pp2
-rw-r--r--manifests/install.pp4
-rw-r--r--manifests/pip.pp34
-rw-r--r--manifests/requirements.pp13
-rw-r--r--manifests/virtualenv.pp14
-rw-r--r--templates/gunicorn.erb28
9 files changed, 87 insertions, 38 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b2bcbe8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+pkg/ \ No newline at end of file
diff --git a/Modulefile b/Modulefile
index 6bfbe7a..5806e9d 100644
--- a/Modulefile
+++ b/Modulefile
@@ -1,5 +1,5 @@
-name 'puppet-python'
-version '1.1.4'
+name 'stankevich-python'
+version '1.2.1'
author 'Sergey Stankevich'
license 'Apache License, Version 2.0'
diff --git a/README.md b/README.md
index 971bbe8..751376a 100644
--- a/README.md
+++ b/README.md
@@ -48,7 +48,7 @@ Installs and manages python, python-dev, python-virtualenv and Gunicorn.
Installs and manages packages from pip.
-**ensure** - present/absent. Default: present
+**ensure** - present/latest/absent. Default: present
**virtualenv** - virtualenv to run pip in. Default: system (no virtualenv)
@@ -60,11 +60,18 @@ Installs and manages packages from pip.
**environment** - Additional environment variables required to install the packages. Default: none
+**egg** - The egg name to use. Default: $name of the class, e.g. cx_Oracle
+
+**install_args** - Array of additional flags to pass to pip during installaton. Default: none
+
+**uninstall_args** - Array of additional flags to pass to pip during uninstall. Default: none
+
python::pip { 'cx_Oracle':
- virtualenv => '/var/www/project1',
- owner => 'appuser',
- proxy => 'http://proxy.domain.com:3128',
- environment => 'ORACLE_HOME=/usr/lib/oracle/11.2/client64',
+ virtualenv => '/var/www/project1',
+ owner => 'appuser',
+ proxy => 'http://proxy.domain.com:3128',
+ environment => 'ORACLE_HOME=/usr/lib/oracle/11.2/client64',
+ install_args => ['-e'],
}
### python::requirements
@@ -77,6 +84,8 @@ Installs and manages Python packages from requirements file.
**owner** - The owner of the virtualenv to ensure that packages are installed with the correct permissions (must be specified). Default: root
+**src** - The ``--src`` parameter to ``pip``, used to specify where to install ``--editable`` resources; by default no ``--src`` parameter is passed to ``pip``.
+
**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.
python::requirements { '/var/www/project1/requirements.txt':
@@ -108,6 +117,10 @@ Creates Python virtualenv.
**index** - Base URL of Python package index. Default: none
+**cwd** - The directory from which to run the "pip install" command. Default: undef
+
+**timeout** - The maximum time in seconds the "pip install" command should take. Default: 1800
+
python::virtualenv { '/var/www/project1':
ensure => present,
version => 'system',
@@ -117,6 +130,8 @@ Creates Python virtualenv.
distribute => false,
owner => 'appuser',
group => 'apps',
+ cwd => '/var/www/project1',
+ timeout => 0,
}
### python::gunicorn
diff --git a/manifests/init.pp b/manifests/init.pp
index 889d9c6..9fe0420 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -44,7 +44,7 @@ class python (
) {
# Module compatibility check
- $compatible = [ 'Debian', 'Ubuntu', 'CentOS', 'RedHat' ]
+ $compatible = [ 'Debian', 'Ubuntu', 'CentOS', 'RedHat', 'Scientific' ]
if ! ($::operatingsystem in $compatible) {
fail("Module is not compatible with ${::operatingsystem}")
}
diff --git a/manifests/install.pp b/manifests/install.pp
index 8bc1b49..0d16659 100644
--- a/manifests/install.pp
+++ b/manifests/install.pp
@@ -6,8 +6,8 @@ class python::install {
}
$pythondev = $::operatingsystem ? {
- /(?i:RedHat|CentOS|Fedora)/ => "${python}-devel",
- /(?i:Debian|Ubuntu)/ => "${python}-dev"
+ /(?i:RedHat|CentOS|Fedora|Scientific)/ => "${python}-devel",
+ /(?i:Debian|Ubuntu)/ => "${python}-dev"
}
$dev_ensure = $python::dev ? {
diff --git a/manifests/pip.pp b/manifests/pip.pp
index 0bed6dc..bcb7911 100644
--- a/manifests/pip.pp
+++ b/manifests/pip.pp
@@ -35,12 +35,15 @@
# Fotis Gimian
#
define python::pip (
- $ensure = present,
- $virtualenv = 'system',
- $url = false,
- $owner = 'root',
- $proxy = false,
- $environment = []
+ $ensure = present,
+ $virtualenv = 'system',
+ $url = false,
+ $owner = 'root',
+ $proxy = false,
+ $egg = false,
+ $environment = [],
+ $install_args = '',
+ $uninstall_args = '',
) {
# Parameter validation
@@ -72,15 +75,20 @@ define python::pip (
default => "^${name}==",
}
+ $egg_name = $egg ? {
+ false => $name,
+ default => $egg
+ }
+
$source = $url ? {
false => $name,
- default => "${url}#egg=${name}",
+ default => "${url}#egg=${egg_name}",
}
case $ensure {
present: {
exec { "pip_install_${name}":
- command => "$pip_env --log ${cwd}/pip.log install ${proxy_flag} ${source}",
+ command => "$pip_env --log ${cwd}/pip.log install $install_args ${proxy_flag} ${source}",
unless => "$pip_env freeze | grep -i -e ${grep_regex}",
user => $owner,
environment => $environment,
@@ -97,9 +105,17 @@ define python::pip (
}
}
+ latest: {
+ exec { "pip_install_${name}":
+ command => "$pip_env --log ${cwd}/pip.log install -U $install_args ${proxy_flag} ${source}",
+ user => $owner,
+ environment => $environment,
+ }
+ }
+
default: {
exec { "pip_uninstall_${name}":
- command => "echo y | $pip_env uninstall ${proxy_flag} ${name}",
+ command => "echo y | $pip_env uninstall $uninstall_args ${proxy_flag} ${name}",
onlyif => "$pip_env freeze | grep -i -e ${grep_regex}",
user => $owner,
environment => $environment,
diff --git a/manifests/requirements.pp b/manifests/requirements.pp
index af84707..60c5b6c 100644
--- a/manifests/requirements.pp
+++ b/manifests/requirements.pp
@@ -19,6 +19,11 @@
# [*proxy*]
# Proxy server to use for outbound connections. Default: none
#
+# [*src*]
+# Pip --src parameter; if the requirements file contains --editable resources,
+# this parameter specifies where they will be installed. See the pip
+# documentation for more. Default: none (i.e. use the pip default).
+#
# [*environment*]
# Additional environment variables required to install the packages. Default: none
#
@@ -41,6 +46,7 @@ define python::requirements (
$owner = 'root',
$group = 'root',
$proxy = false,
+ $src = false,
$environment = []
) {
@@ -63,6 +69,11 @@ define python::requirements (
default => "--proxy=${proxy}",
}
+ $src_flag = $src ? {
+ false => '',
+ default => "--src=${src}",
+ }
+
# This will ensure multiple python::virtualenv definitions can share the
# the same requirements file.
if !defined(File[$requirements]) {
@@ -79,7 +90,7 @@ define python::requirements (
exec { "python_requirements${name}":
provider => shell,
- command => "${pip_env} --log ${cwd}/pip.log install ${proxy_flag} -r ${requirements}",
+ command => "${pip_env} --log-file ${cwd}/pip.log install ${proxy_flag} ${src_flag} -r ${requirements}",
refreshonly => true,
timeout => 1800,
user => $owner,
diff --git a/manifests/virtualenv.pp b/manifests/virtualenv.pp
index 1a2b093..1fb55d6 100644
--- a/manifests/virtualenv.pp
+++ b/manifests/virtualenv.pp
@@ -39,6 +39,12 @@
# [*path*]
# Specifies the PATH variable. Default: [ '/bin', '/usr/bin', '/usr/sbin' ]
#
+# [*cwd*]
+# The directory from which to run the "pip install" command. Default: undef
+#
+# [*timeout*]
+# The maximum time in seconds the "pip install" command should take. Default: 1800
+#
# === Examples
#
# python::virtualenv { '/var/www/project1':
@@ -69,6 +75,8 @@ define python::virtualenv (
$proxy = false,
$environment = [],
$path = [ '/bin', '/usr/bin', '/usr/sbin','/usr/local/bin' ]
+ $cwd = undef,
+ $timeout = 1800
) {
$venv_dir = $name
@@ -124,10 +132,11 @@ define python::virtualenv (
exec { "python_requirements_initial_install_${requirements}_${venv_dir}":
command => "${venv_dir}/bin/pip --log-file ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} -r ${requirements}",
refreshonly => true,
- timeout => 1800,
+ timeout => $timeout,
user => $owner,
subscribe => Exec["python_virtualenv_${venv_dir}"],
environment => $environment,
+ cwd => $cwd
}
python::requirements { "${requirements}_${venv_dir}":
@@ -139,7 +148,6 @@ define python::virtualenv (
require => Exec["python_virtualenv_${venv_dir}"],
}
}
-
} elsif $ensure == 'absent' {
file { $venv_dir:
@@ -148,7 +156,5 @@ define python::virtualenv (
recurse => true,
purge => true,
}
-
}
-
}
diff --git a/templates/gunicorn.erb b/templates/gunicorn.erb
index 1a96531..99481e7 100644
--- a/templates/gunicorn.erb
+++ b/templates/gunicorn.erb
@@ -1,36 +1,36 @@
CONFIG = {
-<% if mode == 'django' -%>
+<% if @mode == 'django' -%>
'mode': 'django',
<% else -%>
'mode': 'wsgi',
<% end -%>
-<% if virtualenv -%>
+<% if @virtualenv -%>
'environment': {
-<% if environment -%>
- 'ENVIRONMENT': '<%= environment %>',
+<% if @environment -%>
+ 'ENVIRONMENT': '<%= @environment %>',
<% end -%>
- 'PYTHONPATH': '<%= virtualenv %>'
+ 'PYTHONPATH': '<%= @virtualenv %>'
},
<% end -%>
- 'working_dir': '<%= dir %>',
+ 'working_dir': '<%= @dir %>',
'user': 'www-data',
'group': 'www-data',
-<% if virtualenv -%>
- 'python': '<%= virtualenv %>/bin/python',
+<% if @virtualenv -%>
+ 'python': '<%= @virtualenv %>/bin/python',
<% else -%>
'python': '/usr/bin/python',
<% end -%>
'args': (
-<% if !virtualenv and !bind -%>
- '--bind=unix:/tmp/gunicorn-<%= name %>.socket',
-<% elsif virtualenv and !bind -%>
- '--bind=unix:<%= virtualenv %>/<%= name %>.socket',
+<% if !@virtualenv and !@bind -%>
+ '--bind=unix:/tmp/gunicorn-<%= @name %>.socket',
+<% elsif @virtualenv and !@bind -%>
+ '--bind=unix:<%= @virtualenv %>/<%= @name %>.socket',
<% else -%>
- '--bind=<%= bind %>',
+ '--bind=<%= @bind %>',
<% end -%>
'--workers=<%= @processorcount.to_i*2 %>',
'--timeout=30',
-<% if mode != 'django' -%>
+<% if @mode != 'django' -%>
'app:app',
<% end -%>
),