From 6b9a5b03dec24ba7226cca02f11684c9910b8186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phanie=20Jaumotte?= Date: Tue, 30 Jul 2024 16:18:55 +0200 Subject: [PATCH] Add a parameter to package mark hold --- manifests/init.pp | 6 +++++- manifests/package.pp | 16 +++++++++++++--- spec/classes/000_elasticsearch_init_spec.rb | 13 +++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index e97ad1217..c245393e2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -184,6 +184,9 @@ # For http, https, and ftp downloads, you may set how long the exec resource # may take. # +# @param package_hold +# Set to hold to tell Debian apt/Solaris pkg to hold the package version. +# # @param package_name # Name Of the package to install. # @@ -430,12 +433,13 @@ String $default_logging_level = $logging_level, Optional[String] $keystore_password = undef, Optional[Stdlib::Absolutepath] $keystore_path = undef, + Stdlib::Filemode $logdir_mode = '2750', + Boolean $package_hold = false, Optional[Stdlib::Absolutepath] $private_key = undef, Enum['rsa','dsa','ec'] $private_key_type = 'rsa', Boolean $restart_config_change = $restart_on_change, Boolean $restart_package_change = $restart_on_change, Boolean $restart_plugin_change = $restart_on_change, - Stdlib::Filemode $logdir_mode = '2750', ) { #### Validate parameters diff --git a/manifests/package.pp b/manifests/package.pp index 3b956a943..93576854b 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -153,9 +153,19 @@ } if ($elasticsearch::package_provider == 'package') { - package { 'elasticsearch': - ensure => $package_ensure, - name => $elasticsearch::_package_name, + # You cannot use "mark" property while "ensure" is one of ["absent", "purged", "held"] + if $package_ensure in ['absent', 'purged', 'held'] { + package { 'elasticsearch': + ensure => $package_ensure, + name => $elasticsearch::_package_name, + } + } else { + # https://puppet.com/docs/puppet/7/types/package.html#package-attribute-mark + package { 'elasticsearch': + ensure => $package_ensure, + name => $elasticsearch::_package_name, + mark => ($elasticsearch::package_hold ? { true => 'hold', false => 'none', }), + } } exec { 'remove_plugin_dir': diff --git a/spec/classes/000_elasticsearch_init_spec.rb b/spec/classes/000_elasticsearch_init_spec.rb index 38e50426c..32f22e46e 100644 --- a/spec/classes/000_elasticsearch_init_spec.rb +++ b/spec/classes/000_elasticsearch_init_spec.rb @@ -437,6 +437,19 @@ end end + describe 'with hold enabled' do + let(:params) do + default_params.merge( + package_hold: true + ) + end + + it { + expect(subject).to contain_package('elasticsearch'). + with(mark: 'hold') + } + end + describe 'running a different user' do let(:params) do default_params.merge(