1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# == Define: python::requirements
#
# Installs and manages Python packages from requirements file.
#
# === Parameters
#
# [*requirements*]
# Path to the requirements file. Defaults to the resource name
#
# [*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
#
# [*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
#
# [*forceupdate*]
# Run a pip install requirements even if we don't receive an event from the
# requirements file - Useful for when the requirements file is written as part of a
# resource other than file (E.g vcsrepo)
#
# === Examples
#
# python::requirements { '/var/www/project1/requirements.txt':
# virtualenv => '/var/www/project1',
# proxy => 'http://proxy.domain.com:3128',
# }
#
# === Authors
#
# Sergey Stankevich
# Ashley Penney
# Fotis Gimian
#
define python::requirements (
$requirements = $name,
$virtualenv = 'system',
$owner = 'root',
$group = 'root',
$proxy = false,
$src = false,
$environment = [],
$forceupdate = false,
) {
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,
}
$pip_env = $virtualenv ? {
'system' => 'pip',
default => "${virtualenv}/bin/pip",
}
$proxy_flag = $proxy ? {
false => '',
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]) {
file { $requirements:
ensure => present,
mode => '0644',
owner => $owner,
group => $group,
audit => content,
replace => false,
content => '# Puppet will install and/or update pip packages listed here',
}
}
exec { "python_requirements${name}":
provider => shell,
command => "${pip_env} --log ${cwd}/pip.log install ${proxy_flag} ${src_flag} -r ${requirements}",
refreshonly => !$forceupdate,
timeout => 1800,
user => $owner,
subscribe => File[$requirements],
environment => $environment,
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
}
}
|