From 8c9db6797bbdb7b17c0cd67224b27999913e1646 Mon Sep 17 00:00:00 2001 From: artonix101 Date: Sun, 25 Oct 2026 19:44:15 +0100 Subject: [PATCH] Replace `params.pp` with module data in Hiera Update spec for params.pp to Hiera conversion --- REFERENCE.md | 13 +++++---- data/common.yaml | 5 ++++ data/os/AIX.yaml | 6 +++++ data/os/Archlinux.yaml | 2 ++ data/os/Fedora.yaml | 1 + data/os/FreeBSD.yaml | 1 + data/os/RedHat.yaml | 2 ++ data/os/RedHat/7.yaml | 1 + manifests/dotfile.pp | 2 +- manifests/init.pp | 14 ++++++---- manifests/params.pp | 45 ------------------------------- manifests/pip.pp | 2 +- manifests/pip/bootstrap.pp | 6 ++--- spec/classes/python_spec.rb | 1 - spec/defines/requirements_spec.rb | 1 - 15 files changed, 38 insertions(+), 64 deletions(-) create mode 100644 data/os/AIX.yaml create mode 100644 data/os/Fedora.yaml create mode 100644 data/os/RedHat.yaml create mode 100644 data/os/RedHat/7.yaml delete mode 100644 manifests/params.pp diff --git a/REFERENCE.md b/REFERENCE.md index cb89ef55..0f3fd922 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -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 @@ -170,7 +169,7 @@ Data type: `Boolean` to determine if the epel class is used. -Default value: `$python::params::use_epel` +Default value: `false` ##### `manage_scl` @@ -212,7 +211,7 @@ Data type: `Boolean` manage the state for package venv -Default value: `$python::params::manage_venv_package` +Default value: `true` ##### `manage_pip_package` @@ -220,7 +219,7 @@ Data type: `Boolean` manage the state for package pip -Default value: `$python::params::manage_pip_package` +Default value: `true` ##### `venv` @@ -236,7 +235,7 @@ Data type: `String[1]` -Default value: `$python::params::gunicorn_package_name` +Default value: `'gunicorn'` ##### `python_pips` @@ -422,7 +421,7 @@ Data type: `String[1]` group owner of dotfile -Default value: `getvar('python::params::group')` +Default value: `lookup('python::group')` ##### `config` @@ -771,7 +770,7 @@ Data type: `Optional[String[1]]` The group of the virtualenv being manipulated. -Default value: `getvar('python::params::group')` +Default value: `lookup('python::group')` ##### `index` diff --git a/data/common.yaml b/data/common.yaml index 8d945465..ed9046ef 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -1 +1,6 @@ +python::group: root +python::pip_lookup_path: + - /bin + - /usr/bin + - /usr/local/bin python::default_system_version: "3.11" diff --git a/data/os/AIX.yaml b/data/os/AIX.yaml new file mode 100644 index 00000000..1b58eb77 --- /dev/null +++ b/data/os/AIX.yaml @@ -0,0 +1,6 @@ +python::group: system +python::pip_lookup_path: + - /bin + - /usr/bin + - /usr/local/bin + - /opt/freeware/bin/ \ No newline at end of file diff --git a/data/os/Archlinux.yaml b/data/os/Archlinux.yaml index 3bd58ed5..c778b5b4 100644 --- a/data/os/Archlinux.yaml +++ b/data/os/Archlinux.yaml @@ -1 +1,3 @@ python::default_system_version: "3.13" +python::manage_pip_package: false +python::manage_venv_package: false diff --git a/data/os/Fedora.yaml b/data/os/Fedora.yaml new file mode 100644 index 00000000..129f6fc0 --- /dev/null +++ b/data/os/Fedora.yaml @@ -0,0 +1 @@ +python::use_epel: false \ No newline at end of file diff --git a/data/os/FreeBSD.yaml b/data/os/FreeBSD.yaml index 8d945465..0dc4a33e 100644 --- a/data/os/FreeBSD.yaml +++ b/data/os/FreeBSD.yaml @@ -1 +1,2 @@ +python::group: wheel python::default_system_version: "3.11" diff --git a/data/os/RedHat.yaml b/data/os/RedHat.yaml new file mode 100644 index 00000000..e07a3cd2 --- /dev/null +++ b/data/os/RedHat.yaml @@ -0,0 +1,2 @@ +python::gunicorn_package_name: python3-gunicorn +python::use_epel: true \ No newline at end of file diff --git a/data/os/RedHat/7.yaml b/data/os/RedHat/7.yaml new file mode 100644 index 00000000..d510b7fe --- /dev/null +++ b/data/os/RedHat/7.yaml @@ -0,0 +1 @@ +python::gunicorn_package_name: python-gunicorn \ No newline at end of file diff --git a/manifests/dotfile.pp b/manifests/dotfile.pp index 06cd2d3a..48d53f88 100644 --- a/manifests/dotfile.pp +++ b/manifests/dotfile.pp @@ -26,7 +26,7 @@ Enum['absent', 'present'] $ensure = 'present', Stdlib::Absolutepath $filename = $title, String[1] $owner = 'root', - String[1] $group = getvar('python::params::group'), + String[1] $group = lookup('python::group'), # lint:ignore:lookup_in_parameter Stdlib::Filemode $mode = '0644', Hash $config = {}, ) { diff --git a/manifests/init.pp b/manifests/init.pp index 31061daf..835563e5 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -49,20 +49,24 @@ Boolean $manage_gunicorn = true, Boolean $manage_python_package = true, Boolean $manage_dev_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, + Boolean $manage_venv_package = true, + Boolean $manage_pip_package = true, + String[1] $gunicorn_package_name = 'gunicorn', 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 $use_epel = false, 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, -) inherits python::params { +) { + unless $facts['os']['family'] in ['AIX', 'Debian', 'FreeBSD', 'Gentoo', 'RedHat', 'Suse', 'Archlinux'] { + fail("Module is not compatible with ${facts['os']['name']}") + } + $exec_prefix = $provider ? { 'scl' => "/usr/bin/scl enable ${version} -- ", 'rhscl' => "/usr/bin/scl enable ${version} -- ", diff --git a/manifests/params.pp b/manifests/params.pp deleted file mode 100644 index 49bfdeac..00000000 --- a/manifests/params.pp +++ /dev/null @@ -1,45 +0,0 @@ -# @api private -# @summary The python Module default configuration settings. -# -# The python Module default configuration settings. -# -class python::params { - # Module compatibility check - unless $facts['os']['family'] in ['AIX', 'Debian', 'FreeBSD', 'Gentoo', 'RedHat', 'Suse', 'Archlinux'] { - fail("Module is not compatible with ${facts['os']['name']}") - } - - if $facts['os']['family'] == 'RedHat' and $facts['os']['name'] != 'Fedora' { - $use_epel = true - } else { - $use_epel = false - } - - $group = $facts['os']['family'] ? { - 'AIX' => 'system', - 'FreeBSD' => 'wheel', - default => 'root' - } - - $pip_lookup_path = $facts['os']['family'] ? { - 'AIX' => ['/bin', '/usr/bin', '/usr/local/bin', '/opt/freeware/bin/',], - default => ['/bin', '/usr/bin', '/usr/local/bin',] - } - - $gunicorn_package_name = $facts['os']['family'] ? { - 'RedHat' => $facts['os']['release']['major'] ? { - '7' => 'python-gunicorn', - default => 'python3-gunicorn', - }, - default => 'gunicorn', - } - - $manage_pip_package = $facts['os']['family'] ? { - 'Archlinux' => false, - default => true, - } - $manage_venv_package = $facts['os']['family'] ? { - 'Archlinux' => false, - default => true, - } -} diff --git a/manifests/pip.pp b/manifests/pip.pp index 99b05ad7..14c0c135 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -55,7 +55,7 @@ String[1] $pip_provider = 'pip', Variant[Boolean, String] $url = false, String[1] $owner = 'root', - Optional[String[1]] $group = getvar('python::params::group'), + Optional[String[1]] $group = lookup('python::group'), # lint:ignore:lookup_in_parameter Optional[Python::Umask] $umask = undef, Variant[Boolean,String[1]] $index = false, Variant[Boolean,String[1]] $extra_index = false, diff --git a/manifests/pip/bootstrap.pp b/manifests/pip/bootstrap.pp index b060a6d0..1620a56d 100644 --- a/manifests/pip/bootstrap.pp +++ b/manifests/pip/bootstrap.pp @@ -14,7 +14,7 @@ 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 { @@ -36,7 +36,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 => lookup('python::pip_lookup_path'), require => Package['python3'], provider => $exec_provider, } @@ -53,7 +53,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 => lookup('python::pip_lookup_path'), require => Package['python'], provider => $exec_provider, } diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index fb68c521..5c6e7faf 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -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') } diff --git a/spec/defines/requirements_spec.rb b/spec/defines/requirements_spec.rb index 82dc0b37..ff8ed7fe 100644 --- a/spec/defines/requirements_spec.rb +++ b/spec/defines/requirements_spec.rb @@ -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') }