summaryrefslogtreecommitdiff
path: root/manifests/requirements.pp
blob: 4dd1f1fe3e8b4edd4f9f363a58ca56627b24c9ea (plain)
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
# == 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
# Ashley Penney
#
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_crc = "${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}"],
  }

}