summaryrefslogtreecommitdiff
path: root/manifests/virtualenv.pp
diff options
context:
space:
mode:
authorSergey Stankevich <sergey.stankevich@gmail.com>2012-09-09 18:36:30 -0400
committerSergey Stankevich <sergey.stankevich@gmail.com>2012-09-09 18:36:30 -0400
commited137893babebabdfdb5adf44d1a52272093ce8b (patch)
treef611108dc849fe8f4372aac981d7e242d59b957b /manifests/virtualenv.pp
Initial import
Diffstat (limited to 'manifests/virtualenv.pp')
-rw-r--r--manifests/virtualenv.pp82
1 files changed, 82 insertions, 0 deletions
diff --git a/manifests/virtualenv.pp b/manifests/virtualenv.pp
new file mode 100644
index 0000000..a5cf12b
--- /dev/null
+++ b/manifests/virtualenv.pp
@@ -0,0 +1,82 @@
+# == Define: python::virtualenv
+#
+# Creates Python virtualenv.
+#
+# === Parameters
+#
+# [*ensure*]
+# present|absent. Default: present
+#
+# [*version*]
+# Python version to use. Default: system default
+#
+# [*requirements*]
+# Path to pip requirements.txt file. Default: none
+#
+# [*proxy*]
+# Proxy server to use for outbound connections. Default: none
+#
+# === Examples
+#
+# python::virtualenv { '/var/www/project1':
+# ensure => present,
+# version => 'system',
+# requirements => '/var/www/project1/requirements.txt',
+# proxy => 'http://proxy.domain.com:3128',
+# }
+#
+# === Authors
+#
+# Sergey Stankevich
+#
+define python::virtualenv (
+ $ensure = present,
+ $version = 'system',
+ $requirements = false,
+ $proxy = false
+) {
+
+ $venv_dir = $name
+
+ if $ensure == 'present' {
+
+ $python = $version ? {
+ 'system' => 'python',
+ default => "python${version}",
+ }
+
+ $proxy_flag = $proxy ? {
+ false => '',
+ default => "--proxy=${proxy}",
+ }
+
+ exec { "python_virtualenv_${venv_dir}":
+ command => "mkdir -p ${venv_dir} \
+ && export http_proxy=${proxy} \
+ && virtualenv -p `which ${python}` ${venv_dir} \
+ && ${venv_dir}/bin/pip install ${proxy_flag} --upgrade distribute pip",
+ creates => $venv_dir,
+ }
+
+ if $requirements {
+ Exec["python_virtualenv_${venv_dir}"]
+ -> Python::Requirements[$requirements]
+
+ python::requirements { $requirements:
+ virtualenv => $venv_dir,
+ proxy => $proxy,
+ }
+ }
+
+ } elsif $ensure == 'absent' {
+
+ file { $venv_dir:
+ ensure => absent,
+ force => true,
+ recurse => true,
+ purge => true,
+ }
+
+ }
+
+}