-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new type is added ```puppet grubby::kernel_opt{'foo': ensure => present, value => 'bar', scope => 'ALL', } ``` The previous hash parameter `grubby::kernel_opts` is still valid and now uses `grubby::kernel_opt` internally. Motivation here is to increase flexibility of module allowing kernel parameters to be added by other distinct modules.
- Loading branch information
1 parent
f163d2e
commit bed1329
Showing
5 changed files
with
210 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# @summary Applies kernel parameter configuration via grubby | ||
# | ||
# @example Add Single Parameter | ||
# grubby::kernel_opt{'keyword':} | ||
# | ||
# @example Delete a Single Parameter | ||
# grubby::kernel_opt{'selinix': | ||
# ensure => 'absent', | ||
# } | ||
# | ||
# @example Add Parameter with Value | ||
# grubby::kernel_opt{'memsize': | ||
# value => '22', | ||
# } | ||
# | ||
# @param opt Kernel option | ||
# @param ensure add or delete kernel option | ||
# @param value Value of kernel option | ||
# @param scope Which kernels to apply parameters to | ||
# | ||
define grubby::kernel_opt ( | ||
Pattern[/\S+/] $opt = $name, | ||
Enum['present', 'absent'] $ensure = 'present', | ||
Variant[Enum['DEFAULT','ALL'],Pattern[/^TITLE=.+$/]] $scope = 'DEFAULT', | ||
Optional[Variant[String[1],Integer]] $value = undef, | ||
){ | ||
|
||
$_opt = $value ? { | ||
Undef => $opt, | ||
default => "${opt}=${value}", | ||
} | ||
|
||
case $ensure { | ||
'present': { | ||
exec { "Ensure ${_opt} kernel option is set for ${scope}": | ||
command => "/sbin/grubby --update-kernel=${scope} --args=${_opt}", | ||
path => ['/bin','/usr/bin'], | ||
unless => "/sbin/grubby --info=${scope} | grep ^args= | test -z \"$(grep -wv ${_opt})\"", | ||
} | ||
} | ||
'absent': { | ||
exec { "Ensure ${opt} kernel option is absent for ${scope}": | ||
command => "/sbin/grubby --update-kernel=${scope} --remove-args=${opt}", | ||
path => ['/bin','/usr/bin'], | ||
unless => "/sbin/grubby --info=${scope} | grep ^args= | test -z \"$(grep -w ${opt})\"", | ||
} | ||
} | ||
default: { | ||
fail('Incorect value of field ensure for ensure parameter!') | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require 'spec_helper' | ||
|
||
describe 'grubby::kernel_opt' do | ||
let(:title) { 'foo' } | ||
|
||
on_supported_os.each do |os, os_facts| | ||
context "on #{os}" do | ||
let(:facts) do | ||
os_facts | ||
end | ||
|
||
it { is_expected.to compile } | ||
context 'with no parameters' do | ||
it do | ||
is_expected.to contain_exec('Ensure foo kernel option is set for DEFAULT').with( | ||
command: '/sbin/grubby --update-kernel=DEFAULT --args=foo', | ||
unless: '/sbin/grubby --info=DEFAULT | grep ^args= | test -z "$(grep -wv foo)"', | ||
) | ||
end | ||
context 'with value and scope set' do | ||
let(:params) do | ||
{ value: 'bar', scope: 'ALL' } | ||
end | ||
|
||
it do | ||
is_expected.to contain_exec('Ensure foo=bar kernel option is set for ALL').with( | ||
command: '/sbin/grubby --update-kernel=ALL --args=foo=bar', | ||
unless: '/sbin/grubby --info=ALL | grep ^args= | test -z "$(grep -wv foo=bar)"', | ||
) | ||
end | ||
end | ||
end | ||
context 'with ensure absent parameters' do | ||
let(:params) do | ||
{ ensure: 'absent' } | ||
end | ||
|
||
it do | ||
is_expected.to contain_exec('Ensure foo kernel option is absent for DEFAULT').with( | ||
command: '/sbin/grubby --update-kernel=DEFAULT --remove-args=foo', | ||
unless: '/sbin/grubby --info=DEFAULT | grep ^args= | test -z "$(grep -w foo)"', | ||
) | ||
end | ||
context 'with value and scope set' do | ||
let(:params) do | ||
super().merge(value: 'bar', scope: 'ALL') | ||
end | ||
|
||
it do | ||
is_expected.to contain_exec('Ensure foo kernel option is absent for ALL').with( | ||
command: '/sbin/grubby --update-kernel=ALL --remove-args=foo', | ||
unless: '/sbin/grubby --info=ALL | grep ^args= | test -z "$(grep -w foo)"', | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters