Defined Type: virtualenv::environment

Defined in:
puppet/modules/virtualenv/manifests/environment.pp

Overview

Class virtualenv

Helper class to install python packages via virtualenv. Will create a virtualenv directory with the given packages.

This is a nasty hack which does not use package providers as puppet does not suppose using those with virtualenv: tickets.puppetlabs.com/browse/PUP-1062

Parameters

ensure

'present' to create the environment, 'absent' to delete it (along with all contents, whether puppet-managed or not)

dir

The directory where the virtual environment should be. Will be created if it does not exist.

packages

An array of pip packages to install during virtualenv creation. Default: undef NOTE: You can also install packages into this virtualenv after creation using the virtualenv::package define.

owner

User owner of the environment directory and created files.

group

Group owner of the environment directory and created files.

timeout

Timeout for the command creating the environment.

python

System python interpreter to use to create the new environment. Default 'python' (i.e. Python2.7).

Parameters:

  • packages (Any) (defaults to: undef)
  • dir (Any) (defaults to: $title)
  • ensure (Any) (defaults to: 'present')
  • owner (Any) (defaults to: 'root')
  • group (Any) (defaults to: 'root')
  • timeout (Any) (defaults to: 300)
  • python (Any) (defaults to: 'python')


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
# File 'puppet/modules/virtualenv/manifests/environment.pp', line 38

define virtualenv::environment (
    $packages  = undef,
    $dir       = $title,
    $ensure    = 'present',
    $owner     = 'root',
    $group     = 'root',
    $timeout   = 300,
    $python    = 'python',
) {
    require ::virtualenv

    require_package([$python, "${python}-dev"])

    if $ensure == 'present' {
        file { $dir:
            ensure => directory,
            owner  => $owner,
            group  => $group,
        }

        exec { "virtualenv-${dir}":
            command => template('virtualenv/create-virtualenv.sh.erb'),
            cwd     => $dir,
            creates => "${dir}/lib",
            user    => $owner,
            group   => $group,
            require => [
                File[$dir],
                Package[$python],
            ],
            timeout => $timeout,
        }
    } elsif $ensure == 'absent' {
        file { $dir:
            ensure  => absent,
            force   => true,
            recurse => true,
            purge   => true,
        }
    }
}