requirements.pp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # == Define: python::requirements
  2. #
  3. # Installs and manages Python packages from requirements file.
  4. #
  5. # === Parameters
  6. #
  7. # [*requirements*]
  8. # Path to the requirements file. Defaults to the resource name
  9. #
  10. # [*virtualenv*]
  11. # virtualenv to run pip in. Default: system-wide
  12. #
  13. # [*owner*]
  14. # The owner of the virtualenv being manipulated. Default: root
  15. #
  16. # [*group*]
  17. # The group relating to the virtualenv being manipulated. Default: root
  18. #
  19. # [*proxy*]
  20. # Proxy server to use for outbound connections. Default: none
  21. #
  22. # [*environment*]
  23. # Additional environment variables required to install the packages. Default: none
  24. #
  25. # === Examples
  26. #
  27. # python::requirements { '/var/www/project1/requirements.txt':
  28. # virtualenv => '/var/www/project1',
  29. # proxy => 'http://proxy.domain.com:3128',
  30. # }
  31. #
  32. # === Authors
  33. #
  34. # Sergey Stankevich
  35. # Ashley Penney
  36. # Fotis Gimian
  37. #
  38. define python::requirements (
  39. $requirements = $name,
  40. $virtualenv = 'system',
  41. $owner = 'root',
  42. $group = 'root',
  43. $proxy = false,
  44. $environment = []
  45. ) {
  46. if $virtualenv == 'system' and ($owner != 'root' or $group != 'root') {
  47. fail('python::pip: root user must be used when virtualenv is system')
  48. }
  49. $cwd = $virtualenv ? {
  50. 'system' => '/',
  51. default => "${virtualenv}",
  52. }
  53. $pip_env = $virtualenv ? {
  54. 'system' => 'pip',
  55. default => "${virtualenv}/bin/pip",
  56. }
  57. $proxy_flag = $proxy ? {
  58. false => '',
  59. default => "--proxy=${proxy}",
  60. }
  61. # This will ensure multiple python::virtualenv definitions can share the
  62. # the same requirements file.
  63. if !defined(File[$requirements]) {
  64. file { $requirements:
  65. ensure => present,
  66. mode => '0644',
  67. owner => $owner,
  68. group => $group,
  69. audit => content,
  70. replace => false,
  71. content => '# Puppet will install and/or update pip packages listed here',
  72. }
  73. }
  74. exec { "python_requirements${name}":
  75. provider => shell,
  76. command => "${pip_env} --log-file ${cwd}/pip.log install ${proxy_flag} -r ${requirements}",
  77. refreshonly => true,
  78. timeout => 1800,
  79. user => $owner,
  80. subscribe => File[$requirements],
  81. environment => $environment,
  82. }
  83. }