Skip to content

Commit 34681cf

Browse files
committed
add option for removing cron provided by distro pkgs
1 parent c999430 commit 34681cf

File tree

7 files changed

+107
-8
lines changed

7 files changed

+107
-8
lines changed

REFERENCE.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ The following parameters are available in the `letsencrypt` class:
8181
* [`renew_post_hook_commands`](#renew_post_hook_commands)
8282
* [`renew_deploy_hook_commands`](#renew_deploy_hook_commands)
8383
* [`renew_additional_args`](#renew_additional_args)
84+
* [`renew_disable_distro_cron`](#renew_disable_distro_cron)
8485
* [`renew_cron_ensure`](#renew_cron_ensure)
8586
* [`renew_cron_hour`](#renew_cron_hour)
8687
* [`renew_cron_minute`](#renew_cron_minute)
@@ -258,6 +259,14 @@ Array of additional command line arguments to pass to 'certbot renew'.
258259

259260
Default value: `[]`
260261

262+
##### <a name="renew_disable_distro_cron"></a>`renew_disable_distro_cron`
263+
264+
Data type: `Any`
265+
266+
Boolean, set to true to disable the cron created by the distro package
267+
268+
Default value: ``true``
269+
261270
##### <a name="renew_cron_ensure"></a>`renew_cron_ensure`
262271

263272
Data type: `Any`
@@ -561,6 +570,8 @@ Note: Hooks set here will run before/after/for ALL certificates, including
561570
any not managed by Puppet. If you want to create hooks for specific
562571
certificates only, create them using letsencrypt::certonly.
563572

573+
will be deleted (unless systemd is used)
574+
564575
#### Parameters
565576

566577
The following parameters are available in the `letsencrypt::renew` class:
@@ -569,6 +580,9 @@ The following parameters are available in the `letsencrypt::renew` class:
569580
* [`post_hook_commands`](#post_hook_commands)
570581
* [`deploy_hook_commands`](#deploy_hook_commands)
571582
* [`additional_args`](#additional_args)
583+
* [`disable_distro_cron`](#disable_distro_cron)
584+
* [`distro_renew_cron_file`](#distro_renew_cron_file)
585+
* [`distro_renew_timer`](#distro_renew_timer)
572586
* [`cron_ensure`](#cron_ensure)
573587
* [`cron_hour`](#cron_hour)
574588
* [`cron_minute`](#cron_minute)
@@ -611,6 +625,30 @@ Array of additional command line arguments to pass to 'certbot renew'.
611625

612626
Default value: `$letsencrypt::renew_additional_args`
613627

628+
##### <a name="disable_distro_cron"></a>`disable_distro_cron`
629+
630+
Data type: `Boolean`
631+
632+
Boolean, set to true to disable the cron created by the distro package
633+
634+
Default value: `$letsencrypt::renew_disable_distro_cron`
635+
636+
##### <a name="distro_renew_cron_file"></a>`distro_renew_cron_file`
637+
638+
Data type: `Optional[Stdlib::Unixpath]`
639+
640+
Optional Unixpath, if set and if disable_distro_cron is true this file
641+
642+
Default value: ``undef``
643+
644+
##### <a name="distro_renew_timer"></a>`distro_renew_timer`
645+
646+
Data type: `Optional[String]`
647+
648+
Optional String, name of the systemd timer to disable if disable_distro_cron is true
649+
650+
Default value: ``undef``
651+
614652
##### <a name="cron_ensure"></a>`cron_ensure`
615653

616654
Data type: `Enum['present', 'absent']`

data/Debian-family.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
letsencrypt::plugin::dns_rfc2136::package_name: 'python3-certbot-dns-rfc2136'
33
letsencrypt::plugin::dns_route53::package_name: 'python3-certbot-dns-route53'
44
letsencrypt::plugin::dns_cloudflare::package_name: 'python3-certbot-dns-cloudflare'
5+
letsencrypt::renew::distro_renew_cron_file: /etc/cron.d/certbot
6+
letsencrypt::renew::distro_renew_timer: certbot.timer

data/FreeBSD-family.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ letsencrypt::cron_owner_group: 'wheel'
55
letsencrypt::plugin::dns_rfc2136::package_name: 'py39-certbot-dns-rfc2136'
66
letsencrypt::plugin::dns_route53::package_name: 'py39-certbot-dns-route53'
77
letsencrypt::plugin::dns_cloudflare::package_name: 'py39-certbot-dns-cloudflare'
8+
letsencrypt::renew::distro_renew_cron_file: /etc/periodic/weekly/500.certbot-3.9

data/RedHat-family.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ letsencrypt::configure_epel: true
33
letsencrypt::plugin::dns_rfc2136::package_name: 'python3-certbot-dns-rfc2136'
44
letsencrypt::plugin::dns_route53::package_name: 'python3-certbot-dns-route53'
55
letsencrypt::plugin::dns_cloudflare::package_name: 'python3-certbot-dns-cloudflare'
6+
letsencrypt::renew::distro_renew_timer: certbot-renew.timer

manifests/init.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
# - $RENEWED_DOMAINS: A space-delimited list of renewed certificate domains.
4040
# Example: "example.com www.example.com"
4141
# @param renew_additional_args Array of additional command line arguments to pass to 'certbot renew'.
42+
# @param renew_disable_distro_cron Boolean, set to true to disable the cron created by the distro package
4243
# @param renew_cron_ensure Intended state of the cron resource running certbot renew.
4344
# @param renew_cron_hour
4445
# Optional string, integer or array of hour(s) the renewal command should run.
@@ -74,6 +75,7 @@
7475
$renew_post_hook_commands = [],
7576
$renew_deploy_hook_commands = [],
7677
$renew_additional_args = [],
78+
$renew_disable_distro_cron = true,
7779
$renew_cron_ensure = 'absent',
7880
$renew_cron_hour = fqdn_rand(24),
7981
$renew_cron_minute = fqdn_rand(60),

manifests/renew.pp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
# - $RENEWED_DOMAINS: A space-delimited list of renewed certificate domains.
1717
# Example: "example.com www.example.com"
1818
# @param additional_args Array of additional command line arguments to pass to 'certbot renew'.
19+
# @param disable_distro_cron Boolean, set to true to disable the cron created by the distro package
20+
# @param distro_renew_cron_file Optional Unixpath, if set and if disable_distro_cron is true this file
21+
# will be deleted (unless systemd is used)
22+
# @param distro_renew_timer Optional String, name of the systemd timer to disable if disable_distro_cron is true
1923
# @param cron_ensure Intended state of the cron resource running certbot renew
2024
# @param cron_hour
2125
# Optional string, integer or array of hour(s) the renewal command should run.
@@ -28,14 +32,17 @@
2832
# run. E.g. '2-30/2' to run on even days. Default: Every day.
2933
#
3034
class letsencrypt::renew (
31-
Variant[String[1], Array[String[1]]] $pre_hook_commands = $letsencrypt::renew_pre_hook_commands,
32-
Variant[String[1], Array[String[1]]] $post_hook_commands = $letsencrypt::renew_post_hook_commands,
33-
Variant[String[1], Array[String[1]]] $deploy_hook_commands = $letsencrypt::renew_deploy_hook_commands,
34-
Array[String[1]] $additional_args = $letsencrypt::renew_additional_args,
35-
Enum['present', 'absent'] $cron_ensure = $letsencrypt::renew_cron_ensure,
36-
Letsencrypt::Cron::Hour $cron_hour = $letsencrypt::renew_cron_hour,
37-
Letsencrypt::Cron::Minute $cron_minute = $letsencrypt::renew_cron_minute,
38-
Letsencrypt::Cron::Monthday $cron_monthday = $letsencrypt::renew_cron_monthday,
35+
Variant[String[1], Array[String[1]]] $pre_hook_commands = $letsencrypt::renew_pre_hook_commands,
36+
Variant[String[1], Array[String[1]]] $post_hook_commands = $letsencrypt::renew_post_hook_commands,
37+
Variant[String[1], Array[String[1]]] $deploy_hook_commands = $letsencrypt::renew_deploy_hook_commands,
38+
Array[String[1]] $additional_args = $letsencrypt::renew_additional_args,
39+
Boolean $disable_distro_cron = $letsencrypt::renew_disable_distro_cron,
40+
Optional[Stdlib::Unixpath] $distro_renew_cron_file = undef,
41+
Optional[String] $distro_renew_timer = undef,
42+
Enum['present', 'absent'] $cron_ensure = $letsencrypt::renew_cron_ensure,
43+
Letsencrypt::Cron::Hour $cron_hour = $letsencrypt::renew_cron_hour,
44+
Letsencrypt::Cron::Minute $cron_minute = $letsencrypt::renew_cron_minute,
45+
Letsencrypt::Cron::Monthday $cron_monthday = $letsencrypt::renew_cron_monthday,
3946
) {
4047
# Directory used for Puppet-managed renewal hooks. Make sure old unmanaged
4148
# hooks in this directory are purged. Leave custom hooks in the default
@@ -84,4 +91,17 @@
8491
minute => $cron_minute,
8592
monthday => $cron_monthday,
8693
}
94+
95+
if $disable_distro_cron and $distro_renew_timer and $facts['service_provider'] == 'systemd' {
96+
service { $distro_renew_timer:
97+
ensure => stopped,
98+
enable => false,
99+
}
100+
}
101+
elsif $disable_distro_cron and $distro_renew_cron_file and $facts['service_provider'] != 'systemd' {
102+
file { $distro_renew_cron_file:
103+
ensure => file,
104+
content => '# certbot renew managed by puppet',
105+
}
106+
}
87107
}

spec/classes/letsencrypt_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,41 @@
211211
end
212212
end
213213

214+
describe 'renew_cron_ensure and disable_distro_cron (with systemd)' do
215+
let(:additional_params) do
216+
{ renew_cron_ensure: 'present' }
217+
end
218+
let(:facts) do
219+
facts.merge({
220+
service_provider: 'systemd',
221+
})
222+
end
223+
224+
it do
225+
case facts[:os]['family']
226+
when 'RedHat'
227+
is_expected.to contain_service('certbot-renew.timer').with(ensure: 'stopped', enable: false)
228+
when 'Debian'
229+
is_expected.to contain_service('certbot.timer').with(ensure: 'stopped', enable: false)
230+
end
231+
end
232+
end
233+
234+
describe 'renew_cron_ensure and disable_distro_cron (without systemd)' do
235+
let(:additional_params) do
236+
{ renew_cron_ensure: 'present' }
237+
end
238+
239+
it do
240+
case facts[:os]['family']
241+
when 'Debian'
242+
is_expected.to contain_file('/etc/cron.d/certbot')
243+
when 'FreeBSD'
244+
is_expected.to contain_file('/etc/periodic/weekly/500.certbot-3.9')
245+
end
246+
end
247+
end
248+
214249
describe 'renew_cron_ensure and additional args' do
215250
let(:additional_params) do
216251
{ renew_cron_ensure: 'present',

0 commit comments

Comments
 (0)