Puppet Class: python

Inherits:
python::params
Defined in:
manifests/init.pp

Summary

Installs and manages python, python-dev, python-virtualenv and gunicorn.

Overview

Examples:

install python from system python

class { 'python':
  version    => 'system',
  pip        => 'present',
  dev        => 'present',
  virtualenv => 'present',
  gunicorn   => 'present',
}

install python3 from scl repo

class { 'python' :
  ensure      => 'present',
  version     => 'rh-python36-python',
  dev         => 'present',
  virtualenv  => 'present',
}

Parameters:

  • ensure (Enum['absent', 'present', 'latest']) (defaults to: $python::params::ensure)

    Desired installation state for the Python package.

  • version (Any) (defaults to: $python::params::version)

    Python version to install. Beware that valid values for this differ a) by the provider you choose and b) by the osfamily/operatingsystem you are using. Allowed values:

    - provider == pip: everything pip allows as a version after the 'python=='
    - else: 'system', 'pypy', 3/3.3/...
       - Be aware that 'system' usually means python 2.X.
       - 'pypy' actually lets us use pypy as python.
       - 3/3.3/... means you are going to install the python3/python3.3/...
         package, if available on your osfamily.
    
  • pip (Enum['absent', 'present', 'latest']) (defaults to: $python::params::pip)

    Desired installation state for the python-pip package.

  • dev (Enum['absent', 'present', 'latest']) (defaults to: $python::params::dev)

    Desired installation state for the python-dev package.

  • virtualenv (Enum['absent', 'present', 'latest']) (defaults to: $python::params::virtualenv)

    Desired installation state for the virtualenv package

  • gunicorn (Enum['absent', 'present', 'latest']) (defaults to: $python::params::gunicorn)

    Desired installation state for Gunicorn.

  • manage_gunicorn (Boolean) (defaults to: $python::params::manage_gunicorn)

    Allow Installation / Removal of Gunicorn.

  • provider (Optional[Enum['pip', 'scl', 'rhscl', 'anaconda', '']]) (defaults to: $python::params::provider)

    What provider to use for installation of the packages, except gunicorn and Python itself.

  • use_epel (Boolean) (defaults to: $python::params::use_epel)

    to determine if the epel class is used.

  • manage_scl (Boolean) (defaults to: $python::params::manage_scl)

    Whether to manage core SCL packages or not.

  • umask (Optional[Pattern[/[0-7]{1,4}/]]) (defaults to: undef)

    The default umask for invoked exec calls.

  • manage_python_package (Boolean) (defaults to: $python::params::manage_python_package)
  • manage_virtualenv_package (Boolean) (defaults to: $python::params::manage_virtualenv_package)
  • manage_pip_package (Boolean) (defaults to: $python::params::manage_pip_package)
  • gunicorn_package_name (Any) (defaults to: $python::params::gunicorn_package_name)
  • valid_versions (Any) (defaults to: $python::params::valid_versions)
  • python_pips (Hash) (defaults to: {})
  • python_virtualenvs (Hash) (defaults to: {})
  • python_pyvenvs (Hash) (defaults to: {})
  • python_requirements (Hash) (defaults to: {})
  • python_dotfiles (Hash) (defaults to: {})
  • rhscl_use_public_repository (Any) (defaults to: $python::params::rhscl_use_public_repository)
  • anaconda_installer_url (Stdlib::Httpurl) (defaults to: $python::params::anaconda_installer_url)
  • anaconda_install_path (Stdlib::Absolutepath) (defaults to: $python::params::anaconda_install_path)


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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'manifests/init.pp', line 38

class python (
  Enum['absent', 'present', 'latest'] $ensure     = $python::params::ensure,
  $version                                        = $python::params::version,
  Enum['absent', 'present', 'latest'] $pip        = $python::params::pip,
  Enum['absent', 'present', 'latest'] $dev        = $python::params::dev,
  Enum['absent', 'present', 'latest'] $virtualenv = $python::params::virtualenv,
  Enum['absent', 'present', 'latest'] $gunicorn   = $python::params::gunicorn,
  Boolean $manage_gunicorn                        = $python::params::manage_gunicorn,
  Boolean $manage_python_package                  = $python::params::manage_python_package,
  Boolean $manage_virtualenv_package              = $python::params::manage_virtualenv_package,
  Boolean $manage_pip_package                     = $python::params::manage_pip_package,
  $gunicorn_package_name                          = $python::params::gunicorn_package_name,
  Optional[Enum['pip', 'scl', 'rhscl', 'anaconda', '']] $provider = $python::params::provider,
  $valid_versions                                 = $python::params::valid_versions,
  Hash $python_pips                               = {},
  Hash $python_virtualenvs                        = {},
  Hash $python_pyvenvs                            = {},
  Hash $python_requirements                       = {},
  Hash $python_dotfiles                           = {},
  Boolean $use_epel                               = $python::params::use_epel,
  $rhscl_use_public_repository                    = $python::params::rhscl_use_public_repository,
  Stdlib::Httpurl $anaconda_installer_url         = $python::params::anaconda_installer_url,
  Stdlib::Absolutepath $anaconda_install_path     = $python::params::anaconda_install_path,
  Boolean $manage_scl                             = $python::params::manage_scl,
  Optional[Pattern[/[0-7]{1,4}/]] $umask          = undef,
) inherits python::params {
  $exec_prefix = $provider ? {
    'scl'   => "/usr/bin/scl enable ${version} -- ",
    'rhscl' => "/usr/bin/scl enable ${version} -- ",
    default => '',
  }

  unless $version =~ Pattern[/\A(python)?[0-9](\.?[0-9])*/,
  /\Apypy\Z/, /\Asystem\Z/, /\Arh-python[0-9]{2}(?:-python)?\Z/] {
    fail("version needs to be pypy, system or a version string like '36', '3.6' or 'python3.6' )")
  }

  # Module compatibility check
  $compatible = ['Debian', 'RedHat', 'Suse', 'Gentoo', 'AIX']
  if ! ($facts['os']['family'] in $compatible) {
    fail("Module is not compatible with ${facts['os']['name']}")
  }

  contain python::install
  contain python::config

  Class['python::install']
  -> Class['python::config']

  # Set default umask.
  if $umask != undef {
    Exec { umask => $umask }
  }

  # Allow hiera configuration of python resources
  create_resources('python::pip', $python_pips)
  create_resources('python::pyvenv', $python_pyvenvs)
  create_resources('python::virtualenv', $python_virtualenvs)
  create_resources('python::requirements', $python_requirements)
  create_resources('python::dotfile', $python_dotfiles)
}