Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
# Garrett Honeycutt <code@garretthoneycutt.com>
#
class python (
$ensure = $python::params::ensure,
$version = $python::params::version,
$pip = $python::params::pip,
$dev = $python::params::dev,
Expand All @@ -76,23 +77,14 @@
"Only 'pip', 'rhscl' and 'scl' are valid providers besides the system default. Detected provider is <${provider}>.")
}

if $provider == 'pip' {
validate_re($version, ['^(2\.[4-7]\.\d|3\.\d\.\d)$','^system$'])
} elsif ($provider == 'scl' or $provider == 'rhscl') {
validate_re($version, concat(['python33', 'python27', 'rh-python34'], $valid_versions))
} else {
validate_re($version, concat(['system', 'pypy'], $valid_versions))
}

$exec_prefix = $provider ? {
'scl' => "scl enable ${version} -- ",
'rhscl' => "scl enable ${version} -- ",
default => '',
}

validate_bool($pip)
validate_bool($dev)
validate_bool($virtualenv)
validate_re($ensure, ['^(absent|present|latest)$'])
validate_re($version, concat(['system', 'pypy'], $valid_versions))
validate_bool($gunicorn)
validate_bool($manage_gunicorn)
validate_bool($use_epel)
Expand Down
98 changes: 63 additions & 35 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,58 +27,70 @@
'Suse' => "${python}-devel",
}

$python_virtualenv = $::lsbdistcodename ? {
'jessie' => 'virtualenv',
default => 'python-virtualenv',
}

# pip version: use only for installation via os package manager!
if $::python::version =~ /^3/ {
$pip = 'python3-pip'
} else {
$pip = 'python-pip'
}

$dev_ensure = $python::dev ? {
true => present,
default => absent,
false => absent,
default => $python::dev,
}

$pip_ensure = $python::pip ? {
true => present,
default => absent,
false => absent,
default => $python::pip,
}

$venv_ensure = $python::virtualenv ? {
true => present,
default => absent,
false => absent,
default => $python::virtualenv,
}

package { 'python':
ensure => $python::ensure,
name => $python,
}

package { 'python-dev':
ensure => $dev_ensure,
name => $pythondev,
}

package { 'pip':
ensure => $pip_ensure,
}

package { 'virtualenv':
ensure => $venv_ensure,
}

# Install latest from pip if pip is the provider
case $python::provider {
pip: {
package { 'virtualenv': ensure => latest, provider => pip }
package { 'pip': ensure => latest, provider => pip }
package { "python==${python::version}": ensure => latest, provider => pip }
Package <| title == 'pip' |> {
name => 'pip',
provider => 'pip',
}
Package <| title == 'virtualenv' |> {
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,
'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'],
package { 'scl-utils':
ensure => latest,
before => Package['python'],
}

# This gets installed as a dependency anyway
# package { "${python::version}-python-virtualenv":
# ensure => $venv_ensure,
Expand Down Expand Up @@ -106,46 +118,62 @@
tag => 'python-scl-repo',
}

package { $::python::version:
ensure => present,
tag => 'python-scl-package',
Package <| title == 'python' |> {
tag => 'python-scl-package',
}

package { "${python::version}-scldev":
ensure => $dev_ensure,
tag => 'python-scl-package',
}

if $pip_ensure {
if $pip_ensure {
exec { 'python-scl-pip-install':
command => "${python::exec_prefix}easy_install pip",
path => ['/usr/bin', '/bin'],
creates => "/opt/rh/${python::version}/root/usr/bin/pip",
}
}

Package <| tag == 'python-scl-repo' |> ->
Package <| tag == 'python-scl-package' |> ->
Exec['python-scl-pip-install']
}

default: {
if $::osfamily == 'RedHat' {
if $pip_ensure == present {
if $python::use_epel == true {
include 'epel'
Class['epel'] -> Package[$pip]
Class['epel'] -> Package['pip']
}
}
if ($venv_ensure == present) and ($::operatingsystemrelease =~ /^6/) {
if $python::use_epel == true {
include 'epel'
Class['epel'] -> Package[$python_virtualenv]
Class['epel'] -> Package['virtualenv']
}
}
}
package { $python_virtualenv: ensure => $venv_ensure }
package { $pip: ensure => $pip_ensure }
package { $pythondev: ensure => $dev_ensure }
package { $python: ensure => present }

if $::python::version =~ /^3/ {
$pip_package = 'python3-pip'
} else {
$pip_package = 'python-pip'
}

$virtualenv_package = $::lsbdistcodename ? {
'jessie' => 'virtualenv',
default => 'python-virtualenv',
}

Package <| title == 'pip' |> {
name => $pip_package,
}

Package <| title == 'virtualenv' |> {
name => $virtualenv_package,
}
}
}

Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# The python Module default configuration settings.
#
class python::params {
$ensure = 'present'
$version = 'system'
$pip = true
$dev = false
Expand Down
Loading