I have a shared puppet reboot block in an init.pp, and also want to have a global parameter of $autorestart which defaults to false so the reboot is globally opt-in. In a subclass I have some resources such as file_line changing settings that normally won't become effective until a reboot occurs, but these do not set the OS flag that a reboot is required (eg writing to audit.rules or sysctl.conf), so have set these to notify => Reboot[after_run].
I know that some of the subclass functions can take effect with service restarts, but that is not what I am try to do here as for example auditd is a protected service.
I have tried putting the global reboot resource in an 'if $autorestart' block, but then the notify on the subclass resource fails to compile if the global $autorestart is set to false. I'm trying to keep this as flexble yet simple as possible.
init.pp:
Boolean $autorestart = false,
…
if $autorestart {
reboot { 'after_run':
apply => 'finished',
timeout => 60,
}
}
subclass.pp:
file_line { 'net.ipv6.conf.all.disable_ipv6':
path => '/etc/sysctl.conf',
line => 'net.ipv6.conf.all.disable_ipv6 = 1',
match => '^net.ipv6.conf.all.disable_ipv6.*',
notify => Reboot['after_run'],
}
error
Could not find resource 'Reboot[after_run]' in parameter 'notify'
I have also tried the puppet-reboot 'onlyif' parameter but this only accepts certain conditions and does not test for the value of a parameter. https://forge.puppet.com/puppetlabs/reboot#reboot-when-certain-conditions-are-met
Any help appreciated.
... but then the notify on the subclass resource fails to compile if the global $autorestart is set to false
That problem would be solved by moving the relationship metaparameter inside the conditional, i.e.
if $autorestart {
reboot { 'after_run':
apply => 'finished',
timeout => 60,
subscribe => File_line['net.ipv6.conf.all.disable_ipv6'], ## ADD THIS
}
}
(And of course remove the notify from your file_line resource.)