Skip to content

Commit

Permalink
Prefer Hiera data to params.pp
Browse files Browse the repository at this point in the history
This limit the quantity of spaghetti code we add when adding support for
another platform.

No functional change.
  • Loading branch information
smortex committed Mar 21, 2023
1 parent 448fcab commit 5ccfca4
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 85 deletions.
34 changes: 14 additions & 20 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

* `python::config`: Optionally installs the gunicorn service
* `python::install`: Installs core python packages
* `python::params`: The python Module default configuration settings.

### Defined types

Expand Down Expand Up @@ -81,8 +80,8 @@ The following parameters are available in the `python` class:
* [`manage_python_package`](#-python--manage_python_package)
* [`manage_venv_package`](#-python--manage_venv_package)
* [`manage_pip_package`](#-python--manage_pip_package)
* [`venv`](#-python--venv)
* [`gunicorn_package_name`](#-python--gunicorn_package_name)
* [`venv`](#-python--venv)
* [`python_pips`](#-python--python_pips)
* [`python_pyvenvs`](#-python--python_pyvenvs)
* [`python_requirements`](#-python--python_requirements)
Expand Down Expand Up @@ -112,8 +111,6 @@ Allowed values:
- 3/3.3/... means you are going to install the python3/python3.3/...
package, if available on your osfamily.

Default value: `$facts['os']['family'] ? { 'Archlinux' => 'system', default => '3'`

##### <a name="-python--pip"></a>`pip`

Data type: `Python::Package::Ensure`
Expand Down Expand Up @@ -160,8 +157,6 @@ Data type: `Boolean`

to determine if the epel class is used.

Default value: `$python::params::use_epel`

##### <a name="-python--manage_scl"></a>`manage_scl`

Data type: `Boolean`
Expand Down Expand Up @@ -198,31 +193,25 @@ Data type: `Boolean`

manage the state for package venv

Default value: `$python::params::manage_venv_package`

##### <a name="-python--manage_pip_package"></a>`manage_pip_package`

Data type: `Boolean`

manage the state for package pip

Default value: `$python::params::manage_pip_package`

##### <a name="-python--venv"></a>`venv`

Data type: `Python::Package::Ensure`
##### <a name="-python--gunicorn_package_name"></a>`gunicorn_package_name`

Data type: `String[1]`


Default value: `'absent'`

##### <a name="-python--gunicorn_package_name"></a>`gunicorn_package_name`
##### <a name="-python--venv"></a>`venv`

Data type: `String[1]`
Data type: `Python::Package::Ensure`



Default value: `$python::params::gunicorn_package_name`
Default value: `'absent'`

##### <a name="-python--python_pips"></a>`python_pips`

Expand Down Expand Up @@ -301,6 +290,7 @@ The following parameters are available in the `python::pip::bootstrap` class:
* [`version`](#-python--pip--bootstrap--version)
* [`manage_python`](#-python--pip--bootstrap--manage_python)
* [`http_proxy`](#-python--pip--bootstrap--http_proxy)
* [`pip_lookup_path`](#-python--pip--bootstrap--pip_lookup_path)
* [`exec_provider`](#-python--pip--bootstrap--exec_provider)

##### <a name="-python--pip--bootstrap--version"></a>`version`
Expand All @@ -327,6 +317,12 @@ Proxy server to use for outbound connections.

Default value: `undef`

##### <a name="-python--pip--bootstrap--pip_lookup_path"></a>`pip_lookup_path`

Data type: `Array[String[1]]`



##### <a name="-python--pip--bootstrap--exec_provider"></a>`exec_provider`

Data type: `String[1]`
Expand Down Expand Up @@ -753,12 +749,10 @@ Default value: `'root'`

##### <a name="-python--pip--group"></a>`group`

Data type: `Optional[String[1]]`
Data type: `String[1]`

The group of the virtualenv being manipulated.

Default value: `getvar('python::params::group')`

##### <a name="-python--pip--index"></a>`index`

Data type: `Variant[Boolean,String[1]]`
Expand Down
11 changes: 11 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
python::version: '3'
python::use_epel: true
python::gunicorn_package_name: 'gunicorn'
python::manage_pip_package: true
python::manage_venv_package: true
python::pip::group: 'root'
python::pip::bootstrap::pip_lookup_path:
- /bin
- /usr/bin
- /usr/local/bin
7 changes: 7 additions & 0 deletions data/os/AIX.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
python::pip::group: 'system'
python::pip::bootstrap::pip_lookup_path:
- /bin
- /usr/bin
- /usr/local/bin
- /opt/freeware/bin/
4 changes: 4 additions & 0 deletions data/os/Archlinux.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
python::version: 'system'
python::manage_pip_package: false
python::manage_venv_package: false
3 changes: 3 additions & 0 deletions data/os/RedHat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
python::use_epel: true
python::gunicorn_package_name: 'python-gunicorn'
2 changes: 2 additions & 0 deletions data/os/RedHat/CentOS/8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
python::gunicorn_package_name: 'python3-gunicorn'
2 changes: 2 additions & 0 deletions data/os/RedHat/Fedora.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
python::use_epel: false
2 changes: 2 additions & 0 deletions data/os/RedHat/RedHat/8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
python::gunicorn_package_name: 'python3-gunicorn'
19 changes: 19 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
version: 5

defaults:
datadir: 'data'
data_hash: 'yaml_data'

hierarchy:
- name: 'family/name/major'
path: 'os/%{facts.os.family}/%{facts.os.name}/%{facts.os.release.major}.yaml'

- name: 'family/name'
path: 'os/%{facts.os.family}/%{facts.os.name}.yaml'

- name: 'family'
path: 'os/%{facts.os.family}.yaml'

- name: 'common'
path: 'common.yaml'
12 changes: 6 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,29 @@
# }
#
class python (
Python::Version $version,
Boolean $manage_venv_package,
Boolean $manage_pip_package,
String[1] $gunicorn_package_name,
Boolean $use_epel,
Python::Package::Ensure $ensure = 'present',
Python::Version $version = $facts['os']['family'] ? { 'Archlinux' => 'system', default => '3' },
Python::Package::Ensure $pip = 'present',
Python::Package::Ensure $dev = 'absent',
Python::Package::Ensure $venv = 'absent',
Python::Package::Ensure $gunicorn = 'absent',
Boolean $manage_gunicorn = true,
Boolean $manage_python_package = true,
Boolean $manage_venv_package = $python::params::manage_venv_package,
Boolean $manage_pip_package = $python::params::manage_pip_package,
String[1] $gunicorn_package_name = $python::params::gunicorn_package_name,
Optional[Python::Provider] $provider = undef,
Hash $python_pips = {},
Hash $python_pyvenvs = {},
Hash $python_requirements = {},
Hash $python_dotfiles = {},
Boolean $use_epel = $python::params::use_epel,
Boolean $rhscl_use_public_repository = true,
Stdlib::Httpurl $anaconda_installer_url = 'https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh',
Stdlib::Absolutepath $anaconda_install_path = '/opt/python',
Boolean $manage_scl = true,
Optional[Python::Umask] $umask = undef,
) inherits python::params {
) {
$exec_prefix = $provider ? {
'scl' => "/usr/bin/scl enable ${version} -- ",
'rhscl' => "/usr/bin/scl enable ${version} -- ",
Expand Down
44 changes: 0 additions & 44 deletions manifests/params.pp

This file was deleted.

2 changes: 1 addition & 1 deletion manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
# }
#
define python::pip (
String[1] $group,
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,
Variant[Boolean,String[1]] $extra_index = false,
Expand Down
7 changes: 4 additions & 3 deletions manifests/pip/bootstrap.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
# }
#
class python::pip::bootstrap (
Array[String[1]] $pip_lookup_path,
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
} else {
Expand All @@ -36,7 +37,7 @@
command => '/usr/bin/curl https://bootstrap.pypa.io/get-pip.py | python3',
environment => $environ,
unless => 'which pip3',
path => $python::params::pip_lookup_path,
path => $pip_lookup_path,
require => Package['python3'],
provider => $exec_provider,
}
Expand All @@ -53,7 +54,7 @@
command => '/usr/bin/curl https://bootstrap.pypa.io/get-pip.py | python',
environment => $environ,
unless => 'which pip',
path => $python::params::pip_lookup_path,
path => $pip_lookup_path,
require => Package['python'],
provider => $exec_provider,
}
Expand Down
1 change: 0 additions & 1 deletion spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
context 'with defaults' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('python::install') }
it { is_expected.to contain_class('python::params') }
it { is_expected.to contain_class('python::config') }
it { is_expected.to contain_package('python') }

Expand Down
3 changes: 0 additions & 3 deletions spec/default_module_facts.yml

This file was deleted.

1 change: 0 additions & 1 deletion spec/defines/requirements_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('python::config') }
it { is_expected.to contain_class('python::install') }
it { is_expected.to contain_class('python::params') }
it { is_expected.to contain_class('python') }
it { is_expected.to contain_exec('python_requirements/requirements.txt') }

Expand Down
6 changes: 0 additions & 6 deletions spec/spec.opts

This file was deleted.

0 comments on commit 5ccfca4

Please sign in to comment.