Skip to content

Commit a7d6ba5

Browse files
committed
Add parameter to manage /etc/udev/rules.d directory
fixes #291
1 parent 5031e05 commit a7d6ba5

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

REFERENCE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ The following parameters are available in the `systemd` class:
144144
* [`manage_oomd`](#-systemd--manage_oomd)
145145
* [`oomd_ensure`](#-systemd--oomd_ensure)
146146
* [`oomd_settings`](#-systemd--oomd_settings)
147+
* [`udev_purge_rules`](#-systemd--udev_purge_rules)
147148

148149
##### <a name="-systemd--default_target"></a>`default_target`
149150

@@ -602,6 +603,14 @@ Hash of systemd-oomd configurations for oomd.conf
602603

603604
Default value: `{}`
604605

606+
##### <a name="-systemd--udev_purge_rules"></a>`udev_purge_rules`
607+
608+
Data type: `Boolean`
609+
610+
Toggle if unmanaged files in /etc/udev/rules.d should be purged if manage_udevd is enabled
611+
612+
Default value: `false`
613+
605614
### <a name="systemd--tmpfiles"></a>`systemd::tmpfiles`
606615

607616
Update the systemd temp files

manifests/init.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@
183183
# @param oomd_settings
184184
# Hash of systemd-oomd configurations for oomd.conf
185185
#
186+
# @param udev_purge_rules
187+
# Toggle if unmanaged files in /etc/udev/rules.d should be purged if manage_udevd is enabled
186188
class systemd (
187189
Optional[Pattern['^.+\.target$']] $default_target = undef,
188190
Hash[String,String] $accounting = {},
@@ -239,6 +241,7 @@
239241
Boolean $manage_oomd = false,
240242
Enum['stopped','running'] $oomd_ensure = 'running',
241243
Systemd::OomdSettings $oomd_settings = {},
244+
Boolean $udev_purge_rules = false,
242245
) {
243246
contain systemd::install
244247

manifests/udevd.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
enable => true,
1010
}
1111

12+
file { '/etc/udev/rules.d':
13+
ensure => directory,
14+
purge => $systemd::udev_purge_rules,
15+
recurse => true,
16+
}
17+
1218
file { '/etc/udev/udev.conf':
1319
ensure => 'file',
1420
owner => 'root',

spec/classes/init_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@
498498
it { is_expected.to compile.with_all_deps }
499499
it { is_expected.not_to contain_service('systemd-udevd') }
500500
it { is_expected.not_to contain_file('/etc/udev/udev.conf') }
501+
it { is_expected.not_to contain_file('/etc/udev/rules.d') }
501502
end
502503

503504
context 'when working with udevd and no custom rules' do
@@ -534,6 +535,8 @@
534535
with_content(%r{^resolve_names=early$}).
535536
with_content(%r{^timeout_signal=SIGKILL$})
536537
}
538+
539+
it { is_expected.to contain_file('/etc/udev/rules.d').with_ensure('directory').with_purge(false) }
537540
end
538541

539542
context 'when working with udevd and a rule set' do
@@ -557,6 +560,18 @@
557560
}
558561
end
559562

563+
context 'when enabling udevd management and rule purging' do
564+
let(:params) do
565+
{
566+
manage_udevd: true,
567+
udev_purge_rules: true,
568+
}
569+
end
570+
571+
it { is_expected.to compile.with_all_deps }
572+
it { is_expected.to contain_file('/etc/udev/rules.d').with_ensure('directory').with_purge(true) }
573+
end
574+
560575
it { is_expected.to compile.with_all_deps }
561576

562577
it {

0 commit comments

Comments
 (0)