diff --git a/REFERENCE.md b/REFERENCE.md index 8f61754e..6cd610a7 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -134,6 +134,7 @@ The following parameters are available in the `systemd` class: * [`udev_resolve_names`](#-systemd--udev_resolve_names) * [`udev_timeout_signal`](#-systemd--udev_timeout_signal) * [`udev_rules`](#-systemd--udev_rules) +* [`udev_reload`](#-systemd--udev_reload) * [`machine_info_settings`](#-systemd--machine_info_settings) * [`manage_logind`](#-systemd--manage_logind) * [`logind_settings`](#-systemd--logind_settings) @@ -525,6 +526,14 @@ Config Hash that is used to generate instances of our Default value: `{}` +##### `udev_reload` + +Data type: `Boolean` + +Whether udev rules should be automatically reloaded upon change. + +Default value: `false` + ##### `machine_info_settings` Data type: `Systemd::MachineInfoSettings` diff --git a/manifests/init.pp b/manifests/init.pp index 56575d24..95aeda78 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -157,6 +157,9 @@ # Config Hash that is used to generate instances of our # `udev::rule` define. # +# @param udev_reload +# Whether udev rules should be automatically reloaded upon change. +# # @param machine_info_settings # Settings to place into /etc/machine-info (hostnamectl) # @@ -261,6 +264,7 @@ Optional[Integer] $udev_event_timeout = undef, Optional[Enum['early', 'late', 'never']] $udev_resolve_names = undef, Optional[Variant[Integer,String]] $udev_timeout_signal = undef, + Boolean $udev_reload = false, Boolean $manage_logind = false, Systemd::LogindSettings $logind_settings = {}, Boolean $manage_all_network_files = false, diff --git a/manifests/udev/rule.pp b/manifests/udev/rule.pp index 06b65c4a..4283cde6 100644 --- a/manifests/udev/rule.pp +++ b/manifests/udev/rule.pp @@ -38,12 +38,22 @@ fail("systemd::udev::rule - ${name}: param rules is empty, you need to pass rules") } + $_notify = if $systemd::udev_reload { + if $notify_services =~ Array { + $notify_services << 'Exec[systemd-udev_reload]' + } else { + [$notify_services, 'Exec[systemd-udev_reload]'] + } + } else { + $notify_services + } + file { join([$path, $name], '/'): ensure => $ensure, owner => 'root', group => 'root', mode => '0444', - notify => $notify_services, + notify => $_notify, selinux_ignore_defaults => $selinux_ignore_defaults, content => epp("${module_name}/udev_rule.epp", { 'rules' => $rules }), } diff --git a/manifests/udevd.pp b/manifests/udevd.pp index 92635b5d..559c7e74 100644 --- a/manifests/udevd.pp +++ b/manifests/udevd.pp @@ -36,4 +36,10 @@ * => $udev_rule, } } + + exec { 'systemd-udev_reload': + command => 'udevadm control --reload-rules && udevadm trigger', + refreshonly => true, + path => $facts['path'], + } } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 1be26d8a..b53ad18a 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -642,6 +642,7 @@ let(:params) do { manage_udevd: true, + udev_reload: true, udev_log: 'daemon', udev_children_max: 1, udev_exec_delay: 2, @@ -664,6 +665,7 @@ { manage_udevd: true, udev_purge_rules: true, + udev_reload: true, } end @@ -701,6 +703,9 @@ 'ACTION=="add", KERNEL=="sdb", RUN+="/bin/raw /dev/raw/raw2 %N"', ]) } + + it { is_expected.to contain_exec('systemd-udev_reload') } + it { is_expected.to contain_file('/etc/udev/rules.d/example_raw.rules').that_notifies('Exec[systemd-udev_reload]') } end context 'with machine-info' do diff --git a/spec/defines/udev_rules_spec.rb b/spec/defines/udev_rules_spec.rb index 05869522..4b37125c 100644 --- a/spec/defines/udev_rules_spec.rb +++ b/spec/defines/udev_rules_spec.rb @@ -88,7 +88,24 @@ class { 'systemd': manage_udevd => true, manage_journald => false } it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify([]) } end - describe 'ensured absent with notify' do + describe 'ensured absent with automatic reload' do + let(:pre_condition) do + <<-PUPPET + class { 'systemd': manage_udevd => true, manage_journald => false, udev_reload => true } + PUPPET + end + let(:params) do + { + ensure: 'absent', + } + end + + it { is_expected.to compile.with_all_deps } + + it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify(['Exec[systemd-udev_reload]']) } + end + + describe 'ensured absent with custom notify' do let(:params) { { ensure: 'absent', notify_services: 'Service[systemd-udevd]', } } it { is_expected.to compile.with_all_deps }