123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- define python::virtualenv (
- $ensure = present,
- $version = 'system',
- $requirements = false,
- $systempkgs = false,
- $distribute = true,
- $index = false,
- $owner = 'root',
- $group = 'root',
- $proxy = false,
- $environment = []
- ) {
- $venv_dir = $name
- if $ensure == 'present' {
- $python = $version ? {
- 'system' => 'python',
- default => "python${version}",
- }
- $proxy_flag = $proxy ? {
- false => '',
- default => "--proxy=${proxy}",
- }
- $proxy_command = $proxy ? {
- false => '',
- default => "&& export http_proxy=${proxy}",
- }
- $system_pkgs_flag = $systempkgs ? {
- false => '',
- default => '--system-site-packages',
- }
- $distribute_pkg = $distribute ? {
- true => 'distribute',
- default => '',
- }
- $pypi_index = $index ? {
- false => '',
- default => "-i ${index}",
- }
- exec { "python_virtualenv_${venv_dir}":
- command => "mkdir -p ${venv_dir} ${proxy_command} && virtualenv ${system_pkgs_flag} ${venv_dir} && ${venv_dir}/bin/pip --log-file ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} --upgrade pip ${distribute_pkg}",
- user => $owner,
- creates => "${venv_dir}/bin/activate",
- path => [ '/bin', '/usr/bin', '/usr/sbin' ],
- cwd => "/tmp",
- environment => $environment,
- }
- if $requirements {
- exec { "python_requirements_initial_install_${requirements}_${venv_dir}":
- command => "${venv_dir}/bin/pip --log-file ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} -r ${requirements}",
- refreshonly => true,
- timeout => 1800,
- user => $owner,
- subscribe => Exec["python_virtualenv_${venv_dir}"],
- environment => $environment,
- }
- python::requirements { "${requirements}_${venv_dir}":
- requirements => $requirements,
- virtualenv => $venv_dir,
- proxy => $proxy,
- owner => $owner,
- group => $group,
- require => Exec["python_virtualenv_${venv_dir}"],
- }
- }
- } elsif $ensure == 'absent' {
- file { $venv_dir:
- ensure => absent,
- force => true,
- recurse => true,
- purge => true,
- }
- }
- }
|