diff --git a/README.md b/README.md index 81617b56..d458c5d4 100644 --- a/README.md +++ b/README.md @@ -278,6 +278,14 @@ python::python_pips: virtualenv: "/opt/env2" ``` +### Using SCL packages from RedHat or CentOS + +To use this module with the Red Hat Software Collections (SCL) or the CentOS +equivalents, set python::provider to 'scl' and python::version to the name of +the collection you want to use (e.g., 'python27', 'python33', or +'rh-python34'). + + ## Authors [Sergey Stankevich](https://github.com/stankevich) | [Shiva Poudel](https://github.com/shivapoudel) | [Garrett Honeycutt](http://learnpuppet.com) diff --git a/manifests/init.pp b/manifests/init.pp index 5d9ed2f7..27ecf09d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -72,12 +72,13 @@ # validate inputs if $provider != undef { - validate_re($provider, ['^pip$'], 'Only "pip" is a valid provider besides the system default.') + validate_re($provider, ['^(pip|scl)$'], 'Only "pip" or "scl" are valid providers besides the system default.') } if $provider == 'pip' { validate_re($version, ['^(2\.[4-7]\.\d|3\.\d\.\d)$','^system$']) - # this will only be checked if not pip, every other string would be rejected by provider check + } elsif $provider == 'scl' { + validate_re($version, concat(['python33', 'python27', 'rh-python34'], $valid_versions)) } else { validate_re($version, concat(['system', 'pypy'], $valid_versions)) } diff --git a/manifests/install.pp b/manifests/install.pp index b9519c83..bec66b3c 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -61,6 +61,46 @@ package { 'pip': ensure => latest, provider => pip } package { "python==${python::version}": ensure => latest, provider => pip } } + scl: { + # SCL is only valid in the RedHat family. If RHEL, package must be + # enabled using the subscription manager outside of puppet. If CentOS, + # the centos-release-SCL will install the repository. + $install_scl_repo_package = $::operatingsystem ? { + 'CentOS' => present, + default => absent, + } + + package { 'centos-release-SCL': + ensure => $install_scl_repo_package, + before => Package['scl-utils'], + } + package { 'scl-utils': ensure => latest, } + package { $::python::version: + ensure => present, + require => Package['scl-utils'], + } + # This gets installed as a dependency anyway + # package { "${python::version}-python-virtualenv": + # ensure => $venv_ensure, + # require => Package['scl-utils'], + # } + package { "${python::version}-scldev": + ensure => $dev_ensure, + require => Package['scl-utils'], + } + # This looks absurd but I can't figure out a better way + $pip_exec_onlyif = $pip_ensure ? { + present => '/bin/true', + default => '/bin/false', + } + exec { 'python-scl-pip-install': + require => Package['scl-utils'], + command => "scl enable ${python::version} -- easy_install pip", + path => ['/usr/bin', '/bin'], + onlyif => $pip_exec_onlyif, + creates => "/opt/rh/${python::version}/root/usr/bin/pip", + } + } default: { if $::osfamily == 'RedHat' { if $pip_ensure == present { diff --git a/manifests/pyvenv.pp b/manifests/pyvenv.pp index 52a3e659..a49b166a 100644 --- a/manifests/pyvenv.pp +++ b/manifests/pyvenv.pp @@ -61,9 +61,12 @@ if $ensure == 'present' { - $virtualenv_cmd = $version ? { - 'system' => 'pyvenv', - default => "pyvenv-${version}", + $virtualenv_cmd = $python::provider ? { + 'scl' => "scl enable ${python::version} -- pyvenv --clear", + default => $version ? { + 'system' => 'pyvenv', + default => "pyvenv-${version}", + } } if ( $systempkgs == true ) {