summaryrefslogtreecommitdiff
path: root/manifests
diff options
context:
space:
mode:
Diffstat (limited to 'manifests')
-rw-r--r--manifests/init.pp5
-rw-r--r--manifests/install.pp12
-rw-r--r--manifests/pip.pp43
-rw-r--r--manifests/requirements.pp27
-rw-r--r--manifests/virtualenv.pp42
5 files changed, 95 insertions, 34 deletions
diff --git a/manifests/init.pp b/manifests/init.pp
index 8e8de9e..2a9a44c 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -7,6 +7,9 @@
# [*version*]
# Python version to install. Default: system default
#
+# [*pip*]
+# Install python-pip. Default: false
+#
# [*dev*]
# Install python-dev. Default: false
#
@@ -20,6 +23,7 @@
#
# class { 'python':
# version => 'system',
+# pip => true,
# dev => true,
# virtualenv => true,
# gunicorn => true,
@@ -31,6 +35,7 @@
#
class python (
$version = 'system',
+ $pip = false,
$dev = false,
$virtualenv = false,
$gunicorn = false
diff --git a/manifests/install.pp b/manifests/install.pp
index cf0a13e..9306e3a 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)/ => "${python}-devel",
+ /(?i:Debian|Ubuntu)/ => "${python}-dev"
}
package { $python: ensure => present }
@@ -17,7 +17,13 @@ class python::install {
default => absent,
}
- package { [ $pythondev, 'python-pip' ]: ensure => $dev_ensure }
+ $pip_ensure = $python::pip ? {
+ true => present,
+ default => absent,
+ }
+
+ package { $pythondev: ensure => $dev_ensure }
+ package { 'python-pip': ensure => $pip_ensure }
$venv_ensure = $python::virtualenv ? {
true => present,
diff --git a/manifests/pip.pp b/manifests/pip.pp
index 3a8ec1b..ddbcd6f 100644
--- a/manifests/pip.pp
+++ b/manifests/pip.pp
@@ -13,9 +13,15 @@
# [*url*]
# URL to install from. Default: none
#
+# [*owner*]
+# The owner of the virtualenv being manipulated. Default: root
+#
# [*proxy*]
# Proxy server to use for outbound connections. Default: none
#
+# [*environment*]
+# Additional environment variables required to install the packages. Default: none
+#
# === Examples
#
# python::pip { 'flask':
@@ -26,12 +32,15 @@
# === Authors
#
# Sergey Stankevich
+# Fotis Gimian
#
define python::pip (
- $virtualenv,
- $ensure = present,
- $url = false,
- $proxy = false
+ $ensure = present,
+ $virtualenv = 'system',
+ $url = false,
+ $owner = 'root',
+ $proxy = false,
+ $environment = []
) {
# Parameter validation
@@ -39,6 +48,20 @@ define python::pip (
fail('python::pip: virtualenv parameter must not be empty')
}
+ if $virtualenv == 'system' and $owner != 'root' {
+ fail('python::pip: root user must be used when virtualenv is system')
+ }
+
+ $cwd = $virtualenv ? {
+ 'system' => '/',
+ default => "${virtualenv}",
+ }
+
+ $pip_env = $virtualenv ? {
+ 'system' => 'pip',
+ default => "${virtualenv}/bin/pip",
+ }
+
$proxy_flag = $proxy ? {
false => '',
default => "--proxy=${proxy}",
@@ -57,15 +80,19 @@ define python::pip (
case $ensure {
present: {
exec { "pip_install_${name}":
- command => "${virtualenv}/bin/pip install ${proxy_flag} ${source}",
- unless => "${virtualenv}/bin/pip freeze | grep -i -e ${grep_regex}",
+ command => "$pip_env --log-file ${cwd}/pip.log install ${proxy_flag} ${source}",
+ unless => "$pip_env freeze | grep -i -e ${grep_regex}",
+ user => $owner,
+ environment => $environment,
}
}
default: {
exec { "pip_uninstall_${name}":
- command => "echo y | ${virtualenv}/bin/pip uninstall ${proxy_flag} ${name}",
- onlyif => "${virtualenv}/bin/pip freeze | grep -i -e ${grep_regex}",
+ command => "echo y | $pip_env uninstall ${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 8b94839..67906fc 100644
--- a/manifests/requirements.pp
+++ b/manifests/requirements.pp
@@ -10,9 +10,18 @@
# [*virtualenv*]
# virtualenv to run pip in. Default: system-wide
#
+# [*owner*]
+# The owner of the virtualenv being manipulated. Default: root
+#
+# [*group*]
+# The group relating to the virtualenv being manipulated. Default: root
+#
# [*proxy*]
# Proxy server to use for outbound connections. Default: none
#
+# [*environment*]
+# Additional environment variables required to install the packages. Default: none
+#
# === Examples
#
# python::requirements { '/var/www/project1/requirements.txt':
@@ -24,22 +33,28 @@
#
# Sergey Stankevich
# Ashley Penney
+# Fotis Gimian
#
define python::requirements (
$requirements = $name,
$virtualenv = 'system',
- $proxy = false,
$owner = 'root',
- $group = 'root'
+ $group = 'root',
+ $proxy = false,
+ $environment = []
) {
+ if $virtualenv == 'system' and ($owner != 'root' or $group != 'root') {
+ fail('python::pip: root user must be used when virtualenv is system')
+ }
+
$cwd = $virtualenv ? {
'system' => '/',
- default => "${virtualenv}/bin/",
+ default => "${virtualenv}",
}
$pip_env = $virtualenv ? {
- 'system' => '`which pip`',
+ 'system' => 'pip',
default => "${virtualenv}/bin/pip",
}
@@ -64,12 +79,12 @@ define python::requirements (
exec { "python_requirements${name}":
provider => shell,
- command => "${pip_env} install ${proxy_flag} -r ${requirements}",
- cwd => $cwd,
+ command => "${pip_env} --log-file ${cwd}/pip.log install ${proxy_flag} -r ${requirements}",
refreshonly => true,
timeout => 1800,
user => $owner,
subscribe => File[$requirements],
+ environment => $environment,
}
}
diff --git a/manifests/virtualenv.pp b/manifests/virtualenv.pp
index fc0f45b..354e4d8 100644
--- a/manifests/virtualenv.pp
+++ b/manifests/virtualenv.pp
@@ -13,15 +13,27 @@
# [*requirements*]
# Path to pip requirements.txt file. Default: none
#
-# [*proxy*]
-# Proxy server to use for outbound connections. Default: none
-#
# [*systempkgs*]
# Copy system site-packages into virtualenv. Default: don't
#
# [*distribute*]
# Include distribute in the virtualenv. Default: true
#
+# [*index*]
+# Base URL of Python package index. Default: none (http://pypi.python.org/simple/)
+#
+# [*owner*]
+# The owner of the virtualenv being manipulated. Default: root
+#
+# [*group*]
+# The group relating to the virtualenv being manipulated. Default: root
+#
+# [*proxy*]
+# Proxy server to use for outbound connections. Default: none
+#
+# [*environment*]
+# Additional environment variables required to install the packages. Default: none
+#
# === Examples
#
# python::virtualenv { '/var/www/project1':
@@ -38,17 +50,19 @@
# Sergey Stankevich
# Ashley Penney
# Marc Fournier
+# Fotis Gimian
#
define python::virtualenv (
$ensure = present,
$version = 'system',
$requirements = false,
- $proxy = false,
$systempkgs = false,
$distribute = true,
+ $index = false,
$owner = 'root',
$group = 'root',
- $index = false,
+ $proxy = false,
+ $environment = []
) {
$venv_dir = $name
@@ -84,29 +98,23 @@ define python::virtualenv (
default => "-i ${index}",
}
-
exec { "python_virtualenv_${venv_dir}":
- command => "mkdir -p ${venv_dir} ${proxy_command} && virtualenv -p `which ${python}` ${system_pkgs_flag} ${venv_dir} && ${venv_dir}/bin/pip install ${pypi_index} ${proxy_flag} --upgrade ${distribute_pkg} pip",
+ command => "mkdir -p ${venv_dir} ${proxy_command} && virtualenv ${system_pkgs_flag} ${venv_dir} && ${venv_dir}/bin/pip --log-file ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} --upgrade ${distribute_pkg} pip",
user => $owner,
- creates => $venv_dir,
+ creates => "${venv_dir}/bin/activate",
path => [ '/bin', '/usr/bin', '/usr/sbin' ],
- }
-
- file{$venv_dir:
- ensure => directory,
- owner => $owner,
- group => $group,
- recurse => true,
- require => Exec["python_virtualenv_${venv_dir}"],
+ cwd => "/tmp",
+ environment => $environment,
}
if $requirements {
exec { "python_requirements_initial_install_${requirements}_${venv_dir}":
- command => "${venv_dir}/bin/pip install ${pypi_index} ${proxy_flag} --requirement ${requirements}",
+ command => "${venv_dir}/bin/pip --log-file ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} -r ${requirements}",
refreshonly => true,
timeout => 1800,
user => $owner,
subscribe => Exec["python_virtualenv_${venv_dir}"],
+ environment => $environment,
}
python::requirements { "${requirements}_${venv_dir}":