From fa27150ce417a99d7e8c85db5f7dbc86bdc3e7eb Mon Sep 17 00:00:00 2001 From: Yorick Poels Date: Wed, 4 Aug 2021 14:33:27 +0200 Subject: [PATCH] Add support for package install options See puppet package resource for more info Better define type Set to undef Add spec test for package_install_options --- manifests/init.pp | 1 + manifests/install.pp | 11 +++++++---- spec/classes/init_spec.rb | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index bebc12b3..e385ed73 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -5,6 +5,7 @@ Enum['absent', 'latest', 'present', 'purged'] $package_ensure = 'present', String[1] $package_name = 'fail2ban', + Optional[Array[String,Hash]] $package_install_options = undef, Optional[Array[String]] $package_list = undef, Stdlib::Absolutepath $config_dir_path = '/etc/fail2ban', diff --git a/manifests/install.pp b/manifests/install.pp index f702dfe9..8da33e6c 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,14 +1,17 @@ # == Class: fail2ban::install -# class fail2ban::install { if $fail2ban::package_name { package { 'fail2ban': - ensure => $fail2ban::package_ensure, - name => $fail2ban::package_name, + ensure => $fail2ban::package_ensure, + name => $fail2ban::package_name, + install_options => $fail2ban::package_install_options, } } if $fail2ban::package_list { - ensure_resource('package', $fail2ban::package_list, { 'ensure' => $fail2ban::package_ensure }) + ensure_resource('package', $fail2ban::package_list, { + 'ensure' => $fail2ban::package_ensure, + 'install_options' => $fail2ban::package_install_options, + }) } } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index dd7c2ace..4a7fcc4e 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -25,6 +25,22 @@ end end + context 'with an install option specified' do + let(:params) { + { + install_options: ['--enablerepo=epel'] + } + } + end + + it do + is_expected.to contain_package('fail2ban').with( + 'ensure' => 'latest', + 'install_options' => ['--enablerepo=epel'] + ) + end + end + context 'when package latest' do let(:params) do { @@ -98,6 +114,25 @@ end end + context ':install_options install package with install options' do + let :facts do + { + osfamily: 'RedHat', + } + end + let :params do + { ensure: 'present', + install_options: ['--enablerepo=epel'] } + end + + it 'Will install the package with install options' do + is_expected.to contain_package('fail2ban').with( + ensure: 'present', + install_options: ['--enablerepo=epel'] + ) + end + end + describe 'fail2ban::config' do context 'defaults' do it do