Skip to content

Commit

Permalink
Add support for package install options
Browse files Browse the repository at this point in the history
See puppet package resource for more info
<https://puppet.com/docs/puppet/7/types/package.html#package-attribute-install_options>

Better define type

Set to undef

Add spec test for package_install_options
  • Loading branch information
yorickps committed Aug 5, 2021
1 parent e65b495 commit fa27150
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 7 additions & 4 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -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,
})
}
}
35 changes: 35 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fa27150

Please sign in to comment.