summaryrefslogtreecommitdiff
path: root/manifests/requirements.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/requirements.pp
Initial import
Diffstat (limited to 'manifests/requirements.pp')
-rw-r--r--manifests/requirements.pp68
1 files changed, 68 insertions, 0 deletions
diff --git a/manifests/requirements.pp b/manifests/requirements.pp
new file mode 100644
index 0000000..e49c86c
--- /dev/null
+++ b/manifests/requirements.pp
@@ -0,0 +1,68 @@
+# == Define: python::requirements
+#
+# Installs and manages Python packages from requirements file.
+#
+# === Parameters
+#
+# [*virtualenv*]
+# virtualenv to run pip in. Default: system-wide
+#
+# [*proxy*]
+# Proxy server to use for outbound connections. Default: none
+#
+# === Examples
+#
+# python::requirements { '/var/www/project1/requirements.txt':
+# virtualenv => '/var/www/project1',
+# proxy => 'http://proxy.domain.com:3128',
+# }
+#
+# === Authors
+#
+# Sergey Stankevich
+#
+define python::requirements (
+ $virtualenv = 'system',
+ $proxy = false
+) {
+
+ $requirements = $name
+
+ $pip_env = $virtualenv ? {
+ 'system' => '`which pip`',
+ default => "${virtualenv}/bin/pip",
+ }
+
+ $proxy_flag = $proxy ? {
+ false => '',
+ default => "--proxy=${proxy}",
+ }
+
+ $req_dir = inline_template('<%= requirements.match(%r!(.+)/.+!)[1] %>')
+ $req_crc = "${req_dir}/requirements.sha1"
+
+ file { $requirements:
+ ensure => present,
+ mode => '0644',
+ owner => 'root',
+ group => 'root',
+ replace => false,
+ content => '# Puppet will install and/or update pip packages listed here',
+ }
+
+ # SHA1 checksum to detect changes
+ exec { "python_requirements_check_${name}":
+ command => "sha1sum ${requirements} > ${req_crc}",
+ unless => "sha1sum -c ${req_crc}",
+ require => File[$requirements],
+ }
+
+ exec { "python_requirements_update_${name}":
+ command => "${pip_env} install ${proxy_flag} -Ur ${requirements}",
+ cwd => $virtualenv,
+ refreshonly => true,
+ timeout => 1800,
+ subscribe => Exec["python_requirements_check_${name}"],
+ }
+
+}