diff --git a/REFERENCE.md b/REFERENCE.md index 069496bd..3bb30293 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1,22 +1,23 @@ # Reference + ## Table of Contents -**Classes** +### Classes -_Public Classes_ +#### Public Classes * [`python`](#python): Installs and manages python, python-dev, python-virtualenv and gunicorn. * [`python::pip::bootstrap`](#pythonpipbootstrap): allow to bootstrap pip when python is managed from other module -_Private Classes_ +#### Private Classes * `python::config`: Optionally installs the gunicorn service * `python::install`: Installs core python packages * `python::params`: The python Module default configuration settings. -**Defined types** +### Defined types * [`python::dotfile`](#pythondotfile): Manages any python dotfiles with a simple config hash. * [`python::gunicorn`](#pythongunicorn): Manages Gunicorn virtual hosts. @@ -25,9 +26,17 @@ _Private Classes_ * [`python::requirements`](#pythonrequirements): Installs and manages Python packages from requirements file. * [`python::virtualenv`](#pythonvirtualenv): Creates Python virtualenv. +### Data types + +* [`Python::Loglevel`](#pythonloglevel): A version type to match all valid versions for python +* [`Python::Package::Ensure`](#pythonpackageensure): A version type to match all valid versions for python +* [`Python::Provider`](#pythonprovider): A version type to match all valid versions for python +* [`Python::Umask`](#pythonumask): A version type to match all valid versions for python +* [`Python::Version`](#pythonversion): A version type to match all valid versions for python + ## Classes -### python +### `python` Installs and manages python, python-dev, python-virtualenv and gunicorn. @@ -62,15 +71,15 @@ The following parameters are available in the `python` class. ##### `ensure` -Data type: `Enum['absent', 'present', 'latest']` +Data type: `Python::Package::Ensure` Desired installation state for the Python package. -Default value: $python::params::ensure +Default value: `$python::params::ensure` ##### `version` -Data type: `Any` +Data type: `Python::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: @@ -81,39 +90,39 @@ Allowed values: - 3/3.3/... means you are going to install the python3/python3.3/... package, if available on your osfamily. -Default value: $python::params::version +Default value: `$python::params::version` ##### `pip` -Data type: `Enum['absent', 'present', 'latest']` +Data type: `Python::Package::Ensure` Desired installation state for the python-pip package. -Default value: $python::params::pip +Default value: `$python::params::pip` ##### `dev` -Data type: `Enum['absent', 'present', 'latest']` +Data type: `Python::Package::Ensure` Desired installation state for the python-dev package. -Default value: $python::params::dev +Default value: `$python::params::dev` ##### `virtualenv` -Data type: `Enum['absent', 'present', 'latest']` +Data type: `Python::Package::Ensure` Desired installation state for the virtualenv package -Default value: $python::params::virtualenv +Default value: `$python::params::virtualenv` ##### `gunicorn` -Data type: `Enum['absent', 'present', 'latest']` +Data type: `Python::Package::Ensure` Desired installation state for Gunicorn. -Default value: $python::params::gunicorn +Default value: `$python::params::gunicorn` ##### `manage_gunicorn` @@ -121,15 +130,15 @@ Data type: `Boolean` Allow Installation / Removal of Gunicorn. -Default value: $python::params::manage_gunicorn +Default value: `$python::params::manage_gunicorn` ##### `provider` -Data type: `Optional[Enum['pip', 'scl', 'rhscl', 'anaconda', '']]` +Data type: `Optional[Python::Provider]` What provider to use for installation of the packages, except gunicorn and Python itself. -Default value: $python::params::provider +Default value: `$python::params::provider` ##### `use_epel` @@ -137,7 +146,7 @@ Data type: `Boolean` to determine if the epel class is used. -Default value: $python::params::use_epel +Default value: `$python::params::use_epel` ##### `manage_scl` @@ -145,15 +154,15 @@ Data type: `Boolean` Whether to manage core SCL packages or not. -Default value: $python::params::manage_scl +Default value: `$python::params::manage_scl` ##### `umask` -Data type: `Optional[Pattern[/[0-7]{1,4}/]]` +Data type: `Optional[Python::Umask]` The default umask for invoked exec calls. -Default value: `undef` +Default value: ``undef`` ##### `manage_python_package` @@ -161,7 +170,7 @@ Data type: `Boolean` -Default value: $python::params::manage_python_package +Default value: `$python::params::manage_python_package` ##### `manage_virtualenv_package` @@ -169,7 +178,7 @@ Data type: `Boolean` -Default value: $python::params::manage_virtualenv_package +Default value: `$python::params::manage_virtualenv_package` ##### `manage_pip_package` @@ -177,23 +186,15 @@ Data type: `Boolean` -Default value: $python::params::manage_pip_package +Default value: `$python::params::manage_pip_package` ##### `gunicorn_package_name` -Data type: `Any` - - - -Default value: $python::params::gunicorn_package_name - -##### `valid_versions` - -Data type: `Any` +Data type: `String[1]` -Default value: $python::params::valid_versions +Default value: `$python::params::gunicorn_package_name` ##### `python_pips` @@ -201,7 +202,7 @@ Data type: `Hash` -Default value: { } +Default value: `{}` ##### `python_virtualenvs` @@ -209,7 +210,7 @@ Data type: `Hash` -Default value: { } +Default value: `{}` ##### `python_pyvenvs` @@ -217,7 +218,7 @@ Data type: `Hash` -Default value: { } +Default value: `{}` ##### `python_requirements` @@ -225,7 +226,7 @@ Data type: `Hash` -Default value: { } +Default value: `{}` ##### `python_dotfiles` @@ -233,15 +234,15 @@ Data type: `Hash` -Default value: { } +Default value: `{}` ##### `rhscl_use_public_repository` -Data type: `Any` +Data type: `Boolean` -Default value: $python::params::rhscl_use_public_repository +Default value: `$python::params::rhscl_use_public_repository` ##### `anaconda_installer_url` @@ -249,7 +250,7 @@ Data type: `Stdlib::Httpurl` -Default value: $python::params::anaconda_installer_url +Default value: `$python::params::anaconda_installer_url` ##### `anaconda_install_path` @@ -257,9 +258,9 @@ Data type: `Stdlib::Absolutepath` -Default value: $python::params::anaconda_install_path +Default value: `$python::params::anaconda_install_path` -### python::pip::bootstrap +### `python::pip::bootstrap` allow to bootstrap pip when python is managed from other module @@ -283,7 +284,7 @@ Data type: `Enum['pip', 'pip3']` should be pip or pip3 -Default value: 'pip' +Default value: `'pip'` ##### `manage_python` @@ -291,7 +292,7 @@ Data type: `Variant[Boolean, String]` if python module will manage deps -Default value: `false` +Default value: ``false`` ##### `http_proxy` @@ -299,7 +300,7 @@ Data type: `Optional[Stdlib::HTTPUrl]` Proxy server to use for outbound connections. -Default value: `undef` +Default value: ``undef`` ##### `exec_provider` @@ -307,11 +308,11 @@ Data type: `String[1]` -Default value: 'shell' +Default value: `'shell'` ## Defined types -### python::dotfile +### `python::dotfile` Manages any python dotfiles with a simple config hash. @@ -343,15 +344,15 @@ Data type: `Enum['absent', 'present']` -Default value: 'present' +Default value: `'present'` ##### `filename` -Data type: `String[1]` +Data type: `Stdlib::Absolutepath` Filename. -Default value: $title +Default value: `$title` ##### `mode` @@ -359,7 +360,7 @@ Data type: `Stdlib::Filemode` File mode. -Default value: '0644' +Default value: `'0644'` ##### `owner` @@ -367,7 +368,7 @@ Data type: `String[1]` user owner of dotfile -Default value: 'root' +Default value: `'root'` ##### `group` @@ -375,7 +376,7 @@ Data type: `String[1]` group owner of dotfile -Default value: 'root' +Default value: `'root'` ##### `config` @@ -383,9 +384,9 @@ Data type: `Hash` Config hash. This will be expanded to an ini-file. -Default value: {} +Default value: `{}` -### python::gunicorn +### `python::gunicorn` Manages Gunicorn virtual hosts. @@ -420,31 +421,31 @@ Data type: `Enum['present', 'absent']` -Default value: present +Default value: `present` ##### `config_dir` -Data type: `Any` +Data type: `Stdlib::Absolutepath` Configure the gunicorn config directory path. -Default value: '/etc/gunicorn.d' +Default value: `'/etc/gunicorn.d'` ##### `manage_config_dir` -Data type: `Any` +Data type: `Booloean` Set if the gunicorn config directory should be created. -Default value: `false` +Default value: ``false`` ##### `virtualenv` -Data type: `Any` +Data type: `Variant[Boolean,Stdlib::Absolutepath]` Run in virtualenv, specify directory. -Default value: `false` +Default value: ``false`` ##### `mode` @@ -452,7 +453,7 @@ Data type: `Enum['wsgi', 'django']` Gunicorn mode. -Default value: 'wsgi' +Default value: `'wsgi'` ##### `dir` @@ -462,119 +463,119 @@ Application directory. ##### `bind` -Data type: `Any` +Data type: `Variant[String[1],Boolean]` Bind on: 'HOST', 'HOST:PORT', 'unix:PATH'. Default: system-wide: unix:/tmp/gunicorn-$name.socket virtualenv: unix:${virtualenv}/${name}.socket -Default value: `false` +Default value: ``false`` ##### `environment` -Data type: `Any` +Data type: `Variant[String[1],Boolean]` Set ENVIRONMENT variable. -Default value: `false` +Default value: ``false`` ##### `appmodule` -Data type: `Any` +Data type: `String[1]` Set the application module name for gunicorn to load when not using Django. -Default value: 'app:app' +Default value: `'app:app'` ##### `osenv` -Data type: `Any` +Data type: `Variant[Boolean,Hash]` Allows setting environment variables for the gunicorn service. Accepts a hash of 'key': 'value' pairs. -Default value: `false` +Default value: ``false`` ##### `timeout` -Data type: `Any` +Data type: `Integer` Allows setting the gunicorn idle worker process time before being killed. The unit of time is seconds. -Default value: 30 +Default value: `30` ##### `template` -Data type: `Any` +Data type: `String[1]` Which ERB template to use. -Default value: 'python/gunicorn.erb' +Default value: `'python/gunicorn.erb'` ##### `args` -Data type: `Any` +Data type: `Array` Custom arguments to add in gunicorn config file. -Default value: [] +Default value: `[]` ##### `owner` -Data type: `Any` +Data type: `String[1]` -Default value: 'www-data' +Default value: `'www-data'` ##### `group` -Data type: `Any` +Data type: `String[1]` -Default value: 'www-data' +Default value: `'www-data'` ##### `workers` -Data type: `Any` +Data type: `Variant[Boolean,Integer]` -Default value: `false` +Default value: ``false`` ##### `access_log_format` -Data type: `Any` +Data type: `Variant[Boolean,String[1]]` -Default value: `false` +Default value: ``false`` ##### `accesslog` -Data type: `Any` +Data type: `Variant[Boolean,Stdlib::Absolutepath]` -Default value: `false` +Default value: ``false`` ##### `errorlog` -Data type: `Any` +Data type: `Variant[Boolean,Stdlib::Absolutepath]` -Default value: `false` +Default value: ``false`` ##### `log_level` -Data type: `Enum['debug', 'info', 'warning', 'error', 'critical']` +Data type: `Python::Loglevel` -Default value: 'error' +Default value: `'error'` -### python::pip +### `python::pip` Installs and manages packages from pip. @@ -628,11 +629,11 @@ must be unique ##### `pkgname` -Data type: `String` +Data type: `String[1]` the name of the package. -Default value: $name +Default value: `$name` ##### `ensure` @@ -640,7 +641,7 @@ Data type: `Variant[Enum[present, absent, latest], String[1]]` Require pip to be available. -Default value: present +Default value: `present` ##### `virtualenv` @@ -648,7 +649,7 @@ Data type: `Variant[Enum['system'], Stdlib::Absolutepath]` virtualenv to run pip in. -Default value: 'system' +Default value: `'system'` ##### `pip_provider` @@ -656,7 +657,7 @@ Data type: `String[1]` version of pip you wish to use. -Default value: 'pip' +Default value: `'pip'` ##### `url` @@ -664,7 +665,7 @@ Data type: `Variant[Boolean, String]` URL to install from. -Default value: `false` +Default value: ``false`` ##### `owner` @@ -672,23 +673,23 @@ Data type: `String[1]` The owner of the virtualenv being manipulated. -Default value: 'root' +Default value: `'root'` ##### `group` -Data type: `Any` +Data type: `Optional[String[1]]` The group of the virtualenv being manipulated. -Default value: getvar('python::params::group') +Default value: `getvar('python::params::group')` ##### `index` -Data type: `Any` +Data type: `Variant[Boolean,String[1]]` Base URL of Python package index. -Default value: `false` +Default value: ``false`` ##### `proxy` @@ -696,7 +697,7 @@ Data type: `Optional[Stdlib::HTTPUrl]` Proxy server to use for outbound connections. -Default value: `undef` +Default value: ``undef`` ##### `editable` @@ -704,23 +705,23 @@ Data type: `Boolean` If true the package is installed as an editable resource. -Default value: `false` +Default value: ``false`` ##### `environment` -Data type: `Any` +Data type: `Array` Additional environment variables required to install the packages. -Default value: [] +Default value: `[]` ##### `extras` -Data type: `Any` +Data type: `Array` Extra features provided by the package which should be installed. -Default value: [] +Default value: `[]` ##### `timeout` @@ -728,7 +729,7 @@ Data type: `Numeric` The maximum time in seconds the "pip install" command should take. -Default value: 1800 +Default value: `1800` ##### `install_args` @@ -736,7 +737,7 @@ Data type: `String` Any additional installation arguments that will be supplied when running pip install. -Default value: '' +Default value: `''` ##### `uninstall_args` @@ -744,7 +745,7 @@ Data type: `String` Any additional arguments that will be supplied when running pip uninstall. -Default value: '' +Default value: `''` ##### `log_dir` @@ -752,7 +753,7 @@ Data type: `String[1]` Log directory -Default value: '/tmp' +Default value: `'/tmp'` ##### `egg` @@ -760,15 +761,15 @@ Data type: `Any` The egg name to use -Default value: `false` +Default value: ``false`` ##### `umask` -Data type: `Any` +Data type: `Optional[Python::Umask]` -Default value: `undef` +Default value: ``undef`` ##### `path` @@ -776,7 +777,7 @@ Data type: `Array[String]` -Default value: ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'] +Default value: `['/usr/local/bin','/usr/bin','/bin', '/usr/sbin']` ##### `exec_provider` @@ -784,9 +785,9 @@ Data type: `String[1]` -Default value: 'shell' +Default value: `'shell'` -### python::pyvenv +### `python::pyvenv` Create a Python3 virtualenv using pyvenv. @@ -811,77 +812,77 @@ The following parameters are available in the `python::pyvenv` defined type. ##### `ensure` -Data type: `Any` +Data type: `Python::Package::Ensure` -Default value: present +Default value: `present` ##### `version` -Data type: `Any` +Data type: `Python::Version` Python version to use. -Default value: 'system' +Default value: `'system'` ##### `systempkgs` -Data type: `Any` +Data type: `Boolean` Copy system site-packages into virtualenv -Default value: `false` +Default value: ``false`` ##### `venv_dir` -Data type: `Any` +Data type: `Stdlib::Absolutepath` Directory to install virtualenv to -Default value: $name +Default value: `$name` ##### `owner` -Data type: `Any` +Data type: `String[1]` The owner of the virtualenv being manipulated -Default value: 'root' +Default value: `'root'` ##### `group` -Data type: `Any` +Data type: `String[1]` The group relating to the virtualenv being manipulated -Default value: 'root' +Default value: `'root'` ##### `mode` -Data type: `Any` +Data type: `Stdlib::Filemode` Optionally specify directory mode -Default value: '0755' +Default value: `'0755'` ##### `path` -Data type: `Any` +Data type: `Array[Stdlib::Absolutepath]` Specifies the PATH variable. -Default value: [ '/bin', '/usr/bin', '/usr/sbin', '/usr/local/bin' ] +Default value: `[ '/bin', '/usr/bin', '/usr/sbin', '/usr/local/bin', ]` ##### `environment` -Data type: `Any` +Data type: `Array` Optionally specify environment variables for pyvenv -Default value: [] +Default value: `[]` -### python::requirements +### `python::requirements` Installs and manages Python packages from requirements file. @@ -904,19 +905,19 @@ The following parameters are available in the `python::requirements` defined typ ##### `requirements` -Data type: `Any` +Data type: `Stdlib::Absolutepath` Path to the requirements file. -Default value: $name +Default value: `$name` ##### `virtualenv` -Data type: `Any` +Data type: `Variant[Enum['system'],Stdlib::Absolutepath]` virtualenv to run pip in. -Default value: 'system' +Default value: `'system'` ##### `pip_provider` @@ -924,23 +925,23 @@ Data type: `Enum['pip', 'pip3']` version of pip you wish to use. -Default value: 'pip' +Default value: `'pip'` ##### `owner` -Data type: `Any` +Data type: `String[1]` The owner of the virtualenv being manipulated. -Default value: 'root' +Default value: `'root'` ##### `group` -Data type: `Any` +Data type: `String[1]` The group relating to the virtualenv being manipulated. -Default value: 'root' +Default value: `'root'` ##### `proxy` @@ -948,7 +949,7 @@ Data type: `Optional[Stdlib::HTTPUrl]` Proxy server to use for outbound connections. -Default value: `undef` +Default value: ``undef`` ##### `src` @@ -956,73 +957,73 @@ Data type: `Any` Pip --src parameter to; if the requirements file contains --editable resources, this parameter specifies where they will be installed. See the pip documentation for more. -Default value: `false` +Default value: ``false`` ##### `environment` -Data type: `Any` +Data type: `Array` Additional environment variables required to install the packages. -Default value: [] +Default value: `[]` ##### `forceupdate` -Data type: `Any` +Data type: `Boolean` Run a pip install requirements even if we don't receive an event from the requirements file - Useful for when the requirements file is written as part of a resource other than file (E.g vcsrepo) -Default value: `false` +Default value: ``false`` ##### `cwd` -Data type: `Any` +Data type: `Stdlib::Absolutepath` The directory from which to run the "pip install" command. -Default value: `undef` +Default value: ``undef`` ##### `extra_pip_args` -Data type: `Any` +Data type: `String` Extra arguments to pass to pip after the requirements file -Default value: '' +Default value: `''` ##### `manage_requirements` -Data type: `Any` +Data type: `Boolean` Create the requirements file if it doesn't exist. -Default value: `true` +Default value: ``true`` ##### `fix_requirements_owner` -Data type: `Any` +Data type: `Boolean` Change owner and group of requirements file. -Default value: `true` +Default value: ``true`` ##### `log_dir` -Data type: `Any` +Data type: `Stdlib::Absolutepath` Log directory. -Default value: '/tmp' +Default value: `'/tmp'` ##### `timeout` -Data type: `Any` +Data type: `Integer` The maximum time in seconds the "pip install" command should take. -Default value: 1800 +Default value: `1800` -### python::virtualenv +### `python::virtualenv` Creates Python virtualenv. @@ -1047,91 +1048,91 @@ The following parameters are available in the `python::virtualenv` defined type. ##### `ensure` -Data type: `Any` +Data type: `Python::Package::Ensure` -Default value: 'present' +Default value: `'present'` ##### `version` -Data type: `Any` +Data type: `Python::Version` Python version to use. -Default value: 'system' +Default value: `'system'` ##### `requirements` -Data type: `Any` +Data type: `Variant[Boolean,Stdlib::Absolutepath]` Path to pip requirements.txt file -Default value: `false` +Default value: ``false`` ##### `systempkgs` -Data type: `Any` +Data type: `Boolean` Copy system site-packages into virtualenv. -Default value: `false` +Default value: ``false`` ##### `venv_dir` -Data type: `Any` +Data type: `Stdlib::Absolutepath` Directory to install virtualenv to -Default value: $name +Default value: `$name` ##### `ensure_venv_dir` -Data type: `Any` +Data type: `Boolean` Create $venv_dir -Default value: `true` +Default value: ``true`` ##### `distribute` -Data type: `Any` +Data type: `Boolean` Include distribute in the virtualenv -Default value: `true` +Default value: ``true`` ##### `index` -Data type: `Any` +Data type: `Variant[Boolean,Stdlib::HTTPUrl]` Base URL of Python package index -Default value: `false` +Default value: ``false`` ##### `owner` -Data type: `Any` +Data type: `String[1]` The owner of the virtualenv being manipulated -Default value: 'root' +Default value: `'root'` ##### `group` -Data type: `Any` +Data type: `String[1]` The group relating to the virtualenv being manipulated -Default value: 'root' +Default value: `'root'` ##### `mode` -Data type: `Any` +Data type: `Stdlib::Filemode` Optionally specify directory mode -Default value: '0755' +Default value: `'0755'` ##### `proxy` @@ -1139,61 +1140,93 @@ Data type: `Optional[Stdlib::HTTPUrl]` Proxy server to use for outbound connections -Default value: `undef` +Default value: ``undef`` ##### `environment` -Data type: `Any` +Data type: `Array` Additional environment variables required to install the packages -Default value: [] +Default value: `[]` ##### `path` -Data type: `Any` +Data type: `Array[Stdlib::Absolutepath]` Specifies the PATH variable -Default value: [ '/bin', '/usr/bin', '/usr/sbin', '/usr/local/bin' ] +Default value: `[ '/bin', '/usr/bin', '/usr/sbin', '/usr/local/bin', ]` ##### `cwd` -Data type: `Any` +Data type: `Optional[Stdlib::Absolutepath]` The directory from which to run the "pip install" command -Default value: `undef` +Default value: ``undef`` ##### `timeout` -Data type: `Any` +Data type: `Integer` The maximum time in seconds the "pip install" command should take -Default value: 1800 +Default value: `1800` ##### `pip_args` -Data type: `Any` +Data type: `String` Arguments to pass to pip during initialization -Default value: '' +Default value: `''` ##### `extra_pip_args` -Data type: `Any` +Data type: `String` Extra arguments to pass to pip after requirements file -Default value: '' +Default value: `''` ##### `virtualenv` -Data type: `Any` +Data type: `Optional[Stdlib::Absolutepath]` + + + +Default value: ``undef`` + +## Data types + +### `Python::Loglevel` + +A version type to match all valid versions for python + +Alias of `Enum['debug', 'info', 'warning', 'error', 'critical']` + +### `Python::Package::Ensure` + +A version type to match all valid versions for python + +Alias of `Enum['absent', 'present', 'latest']` + +### `Python::Provider` + +A version type to match all valid versions for python + +Alias of `Enum['pip', 'scl', 'rhscl', 'anaconda', '']` + +### `Python::Umask` + +A version type to match all valid versions for python + +Alias of `Pattern[/[0-7]{1,4}/]` +### `Python::Version` +A version type to match all valid versions for python -Default value: `undef` +Alias of `Pattern[/\A(python)?[0-9](\.?[0-9])*/, /\Apypy\Z/, /\Asystem\Z/, /\Arh-python[0-9]{2}(?:-python)?\Z/]` diff --git a/manifests/config.pp b/manifests/config.pp index cbb466f1..dfff33b6 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -12,7 +12,7 @@ Python::Virtualenv <| |> -> Python::Pip <| |> if $python::manage_gunicorn { - if $python::gunicorn != 'absent' { + unless $python::gunicorn == 'absent' { Class['python::install'] -> Python::Gunicorn <| |> Python::Gunicorn <| |> ~> Service['gunicorn'] diff --git a/manifests/dotfile.pp b/manifests/dotfile.pp index e42106c1..4961f12f 100644 --- a/manifests/dotfile.pp +++ b/manifests/dotfile.pp @@ -24,11 +24,11 @@ # define python::dotfile ( Enum['absent', 'present'] $ensure = 'present', - String[1] $filename = $title, - String[1] $owner = 'root', - String[1] $group = 'root', - Stdlib::Filemode $mode = '0644', - Hash $config = {}, + Stdlib::Absolutepath $filename = $title, + String[1] $owner = 'root', + String[1] $group = 'root', + Stdlib::Filemode $mode = '0644', + Hash $config = {}, ) { $parent_dir = dirname($filename) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index d9625a04..1b2954be 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -34,26 +34,26 @@ # } # define python::gunicorn ( - Stdlib::Absolutepath $dir, - Enum['present', 'absent'] $ensure = present, - $config_dir = '/etc/gunicorn.d', - $manage_config_dir = false, - $virtualenv = false, - Enum['wsgi', 'django'] $mode = 'wsgi', - $bind = false, - $environment = false, - $owner = 'www-data', - $group = 'www-data', - $appmodule = 'app:app', - $osenv = false, - $timeout = 30, - $workers = false, - $access_log_format = false, - $accesslog = false, - $errorlog = false, - Enum['debug', 'info', 'warning', 'error', 'critical'] $log_level = 'error', - $template = 'python/gunicorn.erb', - $args = [], + Stdlib::Absolutepath $dir, + Enum['present', 'absent'] $ensure = present, + Stdlib::Absolutepath $config_dir = '/etc/gunicorn.d', + Booloean $manage_config_dir = false, + Variant[Boolean,Stdlib::Absolutepath] $virtualenv = false, + Enum['wsgi', 'django'] $mode = 'wsgi', + Variant[String[1],Boolean] $bind = false, + Variant[String[1],Boolean] $environment = false, + String[1] $owner = 'www-data', + String[1] $group = 'www-data', + String[1] $appmodule = 'app:app', + Variant[Boolean,Hash] $osenv = false, + Integer $timeout = 30, + Variant[Boolean,Integer] $workers = false, + Variant[Boolean,String[1]] $access_log_format = false, + Variant[Boolean,Stdlib::Absolutepath] $accesslog = false, + Variant[Boolean,Stdlib::Absolutepath] $errorlog = false, + Python::Loglevel $log_level = 'error', + String[1] $template = 'python/gunicorn.erb', + Array $args = [], ) { if $manage_config_dir { file { $config_dir: @@ -62,6 +62,7 @@ owner => 'root', group => 'root', } + file { "${config_dir}/${name}": ensure => $ensure, mode => '0644', diff --git a/manifests/init.pp b/manifests/init.pp index 468725be..a4cf6957 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -36,30 +36,29 @@ # } # 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, + Python::Package::Ensure $ensure = $python::params::ensure, + Python::Version $version = $python::params::version, + Python::Package::Ensure $pip = $python::params::pip, + Python::Package::Ensure $dev = $python::params::dev, + Python::Package::Ensure $virtualenv = $python::params::virtualenv, + Python::Package::Ensure $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, + String[1] $gunicorn_package_name = $python::params::gunicorn_package_name, + Optional[Python::Provider] $provider = $python::params::provider, + Hash $python_pips = {}, + Hash $python_virtualenvs = {}, + Hash $python_pyvenvs = {}, + Hash $python_requirements = {}, + Hash $python_dotfiles = {}, + Boolean $use_epel = $python::params::use_epel, + Boolean $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[Python::Umask] $umask = undef, ) inherits python::params { $exec_prefix = $provider ? { 'scl' => "/usr/bin/scl enable ${version} -- ", @@ -67,17 +66,6 @@ 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 @@ -85,8 +73,8 @@ -> Class['python::config'] # Set default umask. - if $umask != undef { - Exec { umask => $umask } + exec { default: + umask => $umask } # Allow hiera configuration of python resources diff --git a/manifests/install.pp b/manifests/install.pp index fd063cdf..56ce36ce 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -36,6 +36,7 @@ if $venv_ensure == 'present' { $dev_ensure = 'present' + unless $python::dev { # Error: python2-devel is needed by (installed) python-virtualenv-15.1.0-2.el7.noarch # Python dev is required for virtual environment, but python environment is not required for python dev. @@ -83,7 +84,7 @@ # Respect the $pip_ensure setting unless $pip_ensure == 'absent' { # Install pip without pip, see https://pip.pypa.io/en/stable/installing/. - include 'python::pip::bootstrap' + include python::pip::bootstrap Exec['bootstrap pip'] -> File['pip-python'] -> Package <| provider == pip |> @@ -91,6 +92,7 @@ name => 'pip', provider => 'pip', } + if $pythondev { Package <| title == 'virtualenv' |> { name => 'virtualenv', @@ -119,6 +121,7 @@ ensure => $install_scl_repo_package, before => Package['scl-utils'], } + package { 'scl-utils': ensure => 'present', before => Package['python'], @@ -131,14 +134,10 @@ } } - # This gets installed as a dependency anyway - # package { "${python::version}-python-virtualenv": - # ensure => $venv_ensure, - # require => Package['scl-utils'], - # } package { "${python}-scldevel": ensure => $dev_ensure, } + if $pip_ensure != 'absent' { exec { 'python-scl-pip-install': command => "${python::exec_prefix}easy_install pip", @@ -151,6 +150,7 @@ # rhscl is RedHat SCLs from softwarecollections.org if $python::rhscl_use_public_repository { $scl_package = "rhscl-${python::version}-epel-${facts['os']['release']['major']}-${facts['os']['architecture']}" + package { $scl_package: source => "https://www.softwarecollections.org/en/scls/rhscl/${python::version}/epel-${facts['os']['release']['major']}-${facts['os']['architecture']}/download/${scl_package}.noarch.rpm", provider => 'rpm', @@ -181,8 +181,7 @@ -> Package <| tag == 'python-scl-package' |> } - Package <| tag == 'python-scl-package' |> - -> Package <| tag == 'python-pip-package' |> + Package <| tag == 'python-scl-package' |> -> Package <| tag == 'python-pip-package' |> } 'anaconda': { $installer_path = '/var/tmp/anaconda_installer.sh' @@ -217,6 +216,7 @@ } } } + if $pythondev { package { 'python-dev': ensure => $dev_ensure, @@ -233,6 +233,7 @@ require => Package['python'], } } + if $pythondev { package { 'python-dev': ensure => $dev_ensure, @@ -245,18 +246,12 @@ case $facts['os']['family'] { 'RedHat': { - if $pip_ensure != 'absent' { - if $python::use_epel == true { - include 'epel' - if $python::manage_pip_package { Class['epel'] -> Package['pip'] } - if $python::manage_python_package { Class['epel'] -> Package['python'] } - } + if $pip_ensure != 'absent' and $python::use_epel and ($python::manage_pip_package or $python::manage_python_package) { + require epel } - if ($venv_ensure != 'absent') and ($facts['os']['release']['full'] =~ /^6/) { - if $python::use_epel == true { - include 'epel' - Class['epel'] -> Package['virtualenv'] - } + + if $venv_ensure != 'absent' and $facts['os']['release']['full'] =~ /^6/ and $python::use_epel { + require epel } $virtualenv_package = "${python}-virtualenv" @@ -278,19 +273,19 @@ if String($python::version) =~ /^python3/ { $pip_category = undef - $pip_package = "${python}-pip" + $pip_package = "${python}-pip" $pip_provider = $python.regsubst(/^.*python3\.?/,'pip3.').regsubst(/\.$/,'') } elsif ($facts['os']['family'] == 'RedHat') and (versioncmp($facts['os']['release']['major'], '7') >= 0) { $pip_category = undef - $pip_package = 'python2-pip' + $pip_package = 'python2-pip' $pip_provider = pip2 } elsif $facts['os']['family'] == 'Gentoo' { $pip_category = 'dev-python' - $pip_package = 'pip' + $pip_package = 'pip' $pip_provider = 'pip' } else { $pip_category = undef - $pip_package = 'python-pip' + $pip_package = 'python-pip' $pip_provider = 'pip' } diff --git a/manifests/params.pp b/manifests/params.pp index 8ff6a669..338f9bd9 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -4,28 +4,32 @@ # The python Module default configuration settings. # class python::params { - $ensure = 'present' - $version = 'system' - $pip = 'present' - $dev = 'absent' - $virtualenv = 'absent' - $gunicorn = 'absent' - $manage_gunicorn = true - $manage_python_package = true - $manage_virtualenv_package = true - $manage_pip_package = true - $provider = undef - $valid_versions = undef - $manage_scl = true + # Module compatibility check + unless $facts['os']['family'] in ['Debian', 'RedHat', 'Suse', 'Gentoo', 'AIX',] { + fail("Module is not compatible with ${facts['os']['name']}") + } + + $ensure = 'present' + $version = 'system' + $pip = 'present' + $dev = 'absent' + $virtualenv = 'absent' + $gunicorn = 'absent' + $manage_gunicorn = true + $manage_python_package = true + $manage_virtualenv_package = true + $manage_pip_package = true + $provider = undef + $valid_versions = undef + $manage_scl = true + $rhscl_use_public_repository = true + $anaconda_installer_url = 'https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh' + $anaconda_install_path = '/opt/python' - if $facts['os']['family'] == 'RedHat' { - if $facts['os']['name'] != 'Fedora' { - $use_epel = true - } else { - $use_epel = false - } + if $facts['os']['family'] == 'RedHat' and $facts['os']['name'] != 'Fedora' { + $use_epel = true } else { - $use_epel = false + $use_epel = false } $group = $facts['os']['family'] ? { @@ -34,17 +38,12 @@ } $pip_lookup_path = $facts['os']['family'] ? { - 'AIX' => ['/bin', '/usr/bin', '/usr/local/bin', '/opt/freeware/bin/'], - default => ['/bin', '/usr/bin', '/usr/local/bin'] + 'AIX' => ['/bin', '/usr/bin', '/usr/local/bin', '/opt/freeware/bin/',], + default => ['/bin', '/usr/bin', '/usr/local/bin',] } $gunicorn_package_name = $facts['os']['family'] ? { 'RedHat' => 'python-gunicorn', default => 'gunicorn', } - - $rhscl_use_public_repository = true - - $anaconda_installer_url = 'https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh' - $anaconda_install_path = '/opt/python' } diff --git a/manifests/pip.pp b/manifests/pip.pp index 8f09c95d..30d29ce3 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -48,26 +48,26 @@ # } # define python::pip ( - String $pkgname = $name, - Variant[Enum[present, absent, latest], String[1]] $ensure = present, - Variant[Enum['system'], Stdlib::Absolutepath] $virtualenv = 'system', - String[1] $pip_provider = 'pip', - Variant[Boolean, String] $url = false, - String[1] $owner = 'root', - $group = getvar('python::params::group'), - $umask = undef, - $index = false, - Optional[Stdlib::HTTPUrl] $proxy = undef, - $egg = false, - Boolean $editable = false, - $environment = [], - $extras = [], - String $install_args = '', - String $uninstall_args = '', - Numeric $timeout = 1800, - String[1] $log_dir = '/tmp', - Array[String] $path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'], - String[1] $exec_provider = 'shell', + String[1] $pkgname = $name, + Variant[Enum[present, absent, latest], String[1]] $ensure = present, + Variant[Enum['system'], Stdlib::Absolutepath] $virtualenv = 'system', + String[1] $pip_provider = 'pip', + Variant[Boolean, String] $url = false, + String[1] $owner = 'root', + Optional[String[1]] $group = getvar('python::params::group'), + Optional[Python::Umask] $umask = undef, + Variant[Boolean,String[1]] $index = false, + Optional[Stdlib::HTTPUrl] $proxy = undef, + Any $egg = false, + Boolean $editable = false, + Array $environment = [], + Array $extras = [], + String $install_args = '', + String $uninstall_args = '', + Numeric $timeout = 1800, + String[1] $log_dir = '/tmp', + Array[String] $path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'], + String[1] $exec_provider = 'shell', ) { $python_provider = getparam(Class['python'], 'provider') $python_version = getparam(Class['python'], 'version') @@ -127,7 +127,7 @@ $install_editable = '' } - #TODO: Do more robust argument checking, but below is a start + # TODO: Do more robust argument checking, but below is a start if ($ensure == absent) and ($install_args != '') { fail('python::pip cannot provide install_args with ensure => absent') } @@ -137,15 +137,16 @@ } if $pkgname =~ /==/ { - $parts = split($pkgname, '==') + $parts = split($pkgname, '==') $real_pkgname = $parts[0] + $_ensure = $ensure ? { 'absent' => 'absent', default => $parts[1], } } else { $real_pkgname = $pkgname - $_ensure = $ensure + $_ensure = $ensure } # Check if searching by explicit version. @@ -166,22 +167,22 @@ } $source = $url ? { - false => "${real_pkgname}${extras_string}", - /^(\/|[a-zA-Z]\:)/ => "'${url}'", + false => "${real_pkgname}${extras_string}", + /^(\/|[a-zA-Z]\:)/ => "'${url}'", /^(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp|git)(:\/\/).+$/ => "'${url}'", - default => "'${url}#egg=${egg_name}'", + default => "'${url}#egg=${egg_name}'", } - $pip_install = "${pip_env} --log ${log}/pip.log install" + $pip_install = "${pip_env} --log ${log}/pip.log install" $pip_common_args = "${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source}" # Explicit version out of VCS when PIP supported URL is provided if $source =~ /^'(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp|git)(:\/\/).+'$/ { if $_ensure != present and $_ensure != latest { - $command = "${pip_install} ${install_args} ${pip_common_args}@${_ensure}#egg=${egg_name}" + $command = "${pip_install} ${install_args} ${pip_common_args}@${_ensure}#egg=${egg_name}" $unless_command = "${pip_env} list | grep -i -e '${grep_regex}'" } else { - $command = "${pip_install} ${install_args} ${pip_common_args}" + $command = "${pip_install} ${install_args} ${pip_common_args}" $unless_command = "${pip_env} list | grep -i -e '${grep_regex}'" } } else { @@ -189,13 +190,13 @@ /^((19|20)[0-9][0-9]-(0[1-9]|1[1-2])-([0-2][1-9]|3[0-1])|[0-9]+\.\w+\+?\w*(\.\w+)*)$/: { # Version formats as per http://guide.python-distribute.org/specification.html#standard-versioning-schemes # Explicit version. - $command = "${pip_install} ${install_args} ${pip_common_args}==${_ensure}" + $command = "${pip_install} ${install_args} ${pip_common_args}==${_ensure}" $unless_command = "${pip_env} list | grep -i -e '${grep_regex}'" } 'present': { # Whatever version is available. - $command = "${pip_install} ${pip_common_args}" + $command = "${pip_install} ${pip_common_args}" $unless_command = "${pip_env} list | grep -i -e '${grep_regex}'" } @@ -203,24 +204,28 @@ # Unfortunately this is the smartest way of getting the latest available package version with pip as of now # Note: we DO need to repeat ourselves with "from version" in both grep and sed as on some systems pip returns # more than one line with paretheses. - $latest_version = join(["${pip_install} ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${real_pkgname}==notreallyaversion 2>&1", - ' | grep -oP "\(from versions: .*\)" | sed -E "s/\(from versions: (.*?, )*(.*)\)/\2/g"', - ' | tr -d "[:space:]"']) + $latest_version = join( + ["${pip_install} ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${real_pkgname}==notreallyaversion 2>&1", + ' | grep -oP "\(from versions: .*\)" | sed -E "s/\(from versions: (.*?, )*(.*)\)/\2/g"', + ' | tr -d "[:space:]"',] + ) # Packages with underscores in their names are listed with dashes in their place in `pip freeze` output - $pkgname_with_dashes = regsubst($real_pkgname, '_', '-', 'G') + $pkgname_with_dashes = regsubst($real_pkgname, '_', '-', 'G') $grep_regex_pkgname_with_dashes = "^${pkgname_with_dashes}==" - $installed_version = join(["${pip_env} freeze --all", + $installed_version = join( + ["${pip_env} freeze --all", " | grep -i -e ${grep_regex_pkgname_with_dashes} | cut -d= -f3", - " | tr -d '[:space:]'"]) + " | tr -d '[:space:]'",] + ) - $command = "${pip_install} --upgrade ${pip_common_args}" + $command = "${pip_install} --upgrade ${pip_common_args}" $unless_command = "[ \$(${latest_version}) = \$(${installed_version}) ]" } default: { # Anti-action, uninstall. - $command = "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${name}" + $command = "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${name}" $unless_command = "! ${pip_env} list | grep -i -e '${grep_regex}'" } } diff --git a/manifests/pip/bootstrap.pp b/manifests/pip/bootstrap.pp index 1b69c8ae..b060a6d0 100644 --- a/manifests/pip/bootstrap.pp +++ b/manifests/pip/bootstrap.pp @@ -1,19 +1,19 @@ -# # @summary allow to bootstrap pip when python is managed from other module # # @param version should be pip or pip3 # @param manage_python if python module will manage deps # @param http_proxy Proxy server to use for outbound connections. # -# @example +# @example # class { 'python::pip::bootstrap': # version => 'pip', # } +# class python::pip::bootstrap ( - Enum['pip', 'pip3'] $version = 'pip', - Variant[Boolean, String] $manage_python = false, - Optional[Stdlib::HTTPUrl] $http_proxy = undef, - String[1] $exec_provider = 'shell', + Enum['pip', 'pip3'] $version = 'pip', + Variant[Boolean, String] $manage_python = false, + Optional[Stdlib::HTTPUrl] $http_proxy = undef, + String[1] $exec_provider = 'shell', ) inherits python::params { if $manage_python { include python @@ -40,6 +40,7 @@ require => Package['python3'], provider => $exec_provider, } + # puppet is opinionated about the pip command name file { 'pip3-python': ensure => link, @@ -56,6 +57,7 @@ require => Package['python'], provider => $exec_provider, } + # puppet is opinionated about the pip command name file { 'pip-python': ensure => link, diff --git a/manifests/pyvenv.pp b/manifests/pyvenv.pp index 5b0c91f3..aa9bd0fc 100644 --- a/manifests/pyvenv.pp +++ b/manifests/pyvenv.pp @@ -22,15 +22,15 @@ # } # define python::pyvenv ( - $ensure = present, - $version = 'system', - $systempkgs = false, - $venv_dir = $name, - $owner = 'root', - $group = 'root', - $mode = '0755', - $path = ['/bin', '/usr/bin', '/usr/sbin', '/usr/local/bin'], - $environment = [], + Python::Package::Ensure $ensure = present, + Python::Version $version = 'system', + Boolean $systempkgs = false, + Stdlib::Absolutepath $venv_dir = $name, + String[1] $owner = 'root', + String[1] $group = 'root', + Stdlib::Filemode $mode = '0755', + Array[Stdlib::Absolutepath] $path = ['/bin', '/usr/bin', '/usr/sbin', '/usr/local/bin',], + Array $environment = [], ) { include python @@ -40,15 +40,17 @@ default => $version, } - $python_version_parts = split($python_version, '[.]') + $python_version_parts = split($python_version, '[.]') $normalized_python_version = sprintf('%s.%s', $python_version_parts[0], $python_version_parts[1]) # Debian splits the venv module into a seperate package if ( $facts['os']['family'] == 'Debian') { - $python3_venv_package="python${normalized_python_version}-venv" + $python3_venv_package = "python${normalized_python_version}-venv" + case $facts['os']['distro']['codename'] { - 'xenial','bionic','cosmic','disco','stretch','buster': { - ensure_packages ($python3_venv_package) + 'xenial', 'bionic', 'cosmic', 'disco', 'stretch', 'buster': { + ensure_packages($python3_venv_package) + Package[$python3_venv_package] -> File[$venv_dir] } default: {} @@ -56,7 +58,7 @@ } # pyvenv is deprecated since 3.6 and will be removed in 3.8 - if (versioncmp($normalized_python_version, '3.6') >=0) { + if versioncmp($normalized_python_version, '3.6') >=0 { $virtualenv_cmd = "${python::exec_prefix}python${normalized_python_version} -m venv" } else { $virtualenv_cmd = "${python::exec_prefix}pyvenv-${normalized_python_version}" @@ -67,7 +69,7 @@ default => $path, } - if ( $systempkgs == true ) { + if $systempkgs == true { $system_pkgs_flag = '--system-site-packages' } else { $system_pkgs_flag = '' @@ -80,7 +82,7 @@ mode => $mode, } - $pip_cmd = "${python::exec_prefix}${venv_dir}/bin/pip" + $pip_cmd = "${python::exec_prefix}${venv_dir}/bin/pip" exec { "python_virtualenv_${venv_dir}": command => "${virtualenv_cmd} --clear ${system_pkgs_flag} ${venv_dir} && ${pip_cmd} --log ${venv_dir}/pip.log install --upgrade pip && ${pip_cmd} --log ${venv_dir}/pip.log install --upgrade setuptools", diff --git a/manifests/requirements.pp b/manifests/requirements.pp index e0fbcf2b..836e9097 100644 --- a/manifests/requirements.pp +++ b/manifests/requirements.pp @@ -26,21 +26,21 @@ # } # define python::requirements ( - $requirements = $name, - $virtualenv = 'system', - Enum['pip', 'pip3'] $pip_provider = 'pip', - $owner = 'root', - $group = 'root', - Optional[Stdlib::HTTPUrl] $proxy = undef, - $src = false, - $environment = [], - $forceupdate = false, - $cwd = undef, - $extra_pip_args = '', - $manage_requirements = true, - $fix_requirements_owner = true, - $log_dir = '/tmp', - $timeout = 1800, + Stdlib::Absolutepath $requirements = $name, + Variant[Enum['system'],Stdlib::Absolutepath] $virtualenv = 'system', + Enum['pip', 'pip3'] $pip_provider = 'pip', + String[1] $owner = 'root', + String[1] $group = 'root', + Optional[Stdlib::HTTPUrl] $proxy = undef, + Any $src = false, + Array $environment = [], + Boolean $forceupdate = false, + Stdlib::Absolutepath $cwd = undef, + String $extra_pip_args = '', + Boolean $manage_requirements = true, + Boolean $fix_requirements_owner = true, + Stdlib::Absolutepath $log_dir = '/tmp', + Integer $timeout = 1800, ) { include python @@ -88,6 +88,7 @@ replace => false, content => '# Puppet will install and/or update pip packages listed here', } + $local_subscribe = File[$requirements] } else { $local_subscribe = undef diff --git a/manifests/virtualenv.pp b/manifests/virtualenv.pp index e19cfa3b..ad3910ad 100644 --- a/manifests/virtualenv.pp +++ b/manifests/virtualenv.pp @@ -31,29 +31,30 @@ # } # define python::virtualenv ( - $ensure = 'present', - $version = 'system', - $requirements = false, - $systempkgs = false, - $venv_dir = $name, - $ensure_venv_dir = true, - $distribute = true, - $index = false, - $owner = 'root', - $group = 'root', - $mode = '0755', - Optional[Stdlib::HTTPUrl] $proxy = undef, - $environment = [], - $path = ['/bin', '/usr/bin', '/usr/sbin', '/usr/local/bin'], - $cwd = undef, - $timeout = 1800, - $pip_args = '', - $extra_pip_args = '', - $virtualenv = undef, + Python::Package::Ensure $ensure = 'present', + Python::Version $version = 'system', + Variant[Boolean,Stdlib::Absolutepath] $requirements = false, + Boolean $systempkgs = false, + Stdlib::Absolutepath $venv_dir = $name, + Boolean $ensure_venv_dir = true, + Boolean $distribute = true, + Variant[Boolean,Stdlib::HTTPUrl] $index = false, + String[1] $owner = 'root', + String[1] $group = 'root', + Stdlib::Filemode $mode = '0755', + Optional[Stdlib::HTTPUrl] $proxy = undef, + Array $environment = [], + Array[Stdlib::Absolutepath] $path = ['/bin', '/usr/bin', '/usr/sbin', '/usr/local/bin',], + Optional[Stdlib::Absolutepath] $cwd = undef, + Integer $timeout = 1800, + String $pip_args = '', + String $extra_pip_args = '', + Optional[Stdlib::Absolutepath] $virtualenv = undef, ) { include python + $python_provider = getparam(Class['python'], 'provider') - $anaconda_path = getparam(Class['python'], 'anaconda_install_path') + $anaconda_path = getparam(Class['python'], 'anaconda_install_path') if $ensure == 'present' { $python = $version ? { @@ -81,8 +82,14 @@ $proxy_hash = $proxy ? { undef => {}, default => $facts['os']['family'] ? { - 'AIX' => { 'http_proxy' => $proxy, 'https_proxy' => $proxy }, - default => { 'HTTP_PROXY' => $proxy, 'HTTPS_PROXY' => $proxy }, + 'AIX' => { + 'http_proxy' => $proxy, + 'https_proxy' => $proxy, + }, + default => { + 'HTTP_PROXY' => $proxy, + 'HTTPS_PROXY' => $proxy, + }, } } @@ -94,15 +101,15 @@ /.*/ => getvar('virtualenv_version'), default => '', } - if (( versioncmp($_virtualenv_version,'1.7') > 0 ) and ( $systempkgs == true )) { + + if versioncmp($_virtualenv_version,'1.7') > 0 and $systempkgs == true { $system_pkgs_flag = '--system-site-packages' - } elsif (( versioncmp($_virtualenv_version,'1.7') < 0 ) and ( $systempkgs == false )) { + } elsif versioncmp($_virtualenv_version,'1.7') < 0 and $systempkgs == false { $system_pkgs_flag = '--no-site-packages' } else { $system_pkgs_flag = $systempkgs ? { true => '--system-site-packages', - false => '--no-site-packages', - default => fail('Invalid value for systempkgs. Boolean value is expected') + default => '--no-site-packages', } } @@ -110,6 +117,7 @@ true => 'distribute', default => 'setuptools', } + $pypi_index = $index ? { false => '', default => "-i ${index}", @@ -132,9 +140,8 @@ } $virtualenv_cmd = "${python::exec_prefix}${used_virtualenv}" - - $pip_cmd = "${python::exec_prefix}${venv_dir}/bin/pip" - $pip_flags = "${pypi_index} ${proxy_flag} ${pip_args}" + $pip_cmd = "${python::exec_prefix}${venv_dir}/bin/pip" + $pip_flags = "${pypi_index} ${proxy_flag} ${pip_args}" exec { "python_virtualenv_${venv_dir}": command => "${virtualenv_cmd} ${system_pkgs_flag} -p ${python} ${venv_dir} && ${pip_cmd} --log ${venv_dir}/pip.log install ${pip_flags} --upgrade pip && ${pip_cmd} install ${pip_flags} --upgrade ${distribute_pkg}", diff --git a/types/loglevel.pp b/types/loglevel.pp new file mode 100644 index 00000000..3cdb653d --- /dev/null +++ b/types/loglevel.pp @@ -0,0 +1,3 @@ +# @summary A version type to match all valid loglevels for python +# +type Python::Loglevel = Enum['debug', 'info', 'warning', 'error', 'critical'] diff --git a/types/package/ensure.pp b/types/package/ensure.pp new file mode 100644 index 00000000..1eb13b82 --- /dev/null +++ b/types/package/ensure.pp @@ -0,0 +1,3 @@ +# @summary A version type to match all valid package ensures for python +# +type Python::Package::Ensure = Enum['absent', 'present', 'latest'] diff --git a/types/provider.pp b/types/provider.pp new file mode 100644 index 00000000..8c7dfd65 --- /dev/null +++ b/types/provider.pp @@ -0,0 +1,3 @@ +# @summary A version type to match all valid provider for python +# +type Python::Provider = Enum['pip', 'scl', 'rhscl', 'anaconda', ''] diff --git a/types/umask.pp b/types/umask.pp new file mode 100644 index 00000000..11296cd0 --- /dev/null +++ b/types/umask.pp @@ -0,0 +1,3 @@ +# @summary A version type to match valid umask for python +# +type Python::Umask = Pattern[/[0-7]{1,4}/] diff --git a/types/version.pp b/types/version.pp new file mode 100644 index 00000000..e0023aef --- /dev/null +++ b/types/version.pp @@ -0,0 +1,8 @@ +# @summary A version type to match all valid versions for python +# +type Python::Version = Pattern[ + /\A(python)?[0-9](\.?[0-9])*/, + /\Apypy\Z/, + /\Asystem\Z/, + /\Arh-python[0-9]{2}(?:-python)?\Z/ +]