Skip to content

Commit

Permalink
Add environment parameter to renew cron
Browse files Browse the repository at this point in the history
  • Loading branch information
gmenuel committed May 11, 2022
1 parent a03cf71 commit 6da637d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
20 changes: 20 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ The following parameters are available in the `letsencrypt` class:
* [`renew_cron_hour`](#renew_cron_hour)
* [`renew_cron_minute`](#renew_cron_minute)
* [`renew_cron_monthday`](#renew_cron_monthday)
* [`renew_cron_environment`](#renew_cron_environment)

##### <a name="email"></a>`email`

Expand Down Expand Up @@ -294,6 +295,15 @@ run. E.g. '2-30/2' to run on even days.

Default value: `'*'`

##### <a name="renew_cron_environment"></a>`renew_cron_environment`

Data type: `Any`

Optional string or array of environments(s) the renewal command should have.
E.g. PATH=/sbin:/usr/sbin:/bin:/usr/bin

Default value: ``undef``

### <a name="letsencryptinstall"></a>`letsencrypt::install`

Installs the Let's Encrypt client.
Expand Down Expand Up @@ -573,6 +583,7 @@ The following parameters are available in the `letsencrypt::renew` class:
* [`cron_hour`](#cron_hour)
* [`cron_minute`](#cron_minute)
* [`cron_monthday`](#cron_monthday)
* [`cron_environment`](#cron_environment)

##### <a name="pre_hook_commands"></a>`pre_hook_commands`

Expand Down Expand Up @@ -646,6 +657,15 @@ run. E.g. '2-30/2' to run on even days. Default: Every day.

Default value: `$letsencrypt::renew_cron_monthday`

##### <a name="cron_environment"></a>`cron_environment`

Data type: `Variant[String, Array[String], Undef]`

Optional string or array of environments(s) the renewal command should have.
E.g. PATH=/sbin:/usr/sbin:/bin:/usr/bin

Default value: `$letsencrypt::renew_cron_environment`

## Defined types

### <a name="letsencryptcertonly"></a>`letsencrypt::certonly`
Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
# @param renew_cron_monthday
# Optional string, integer or array of monthday(s) the renewal command should
# run. E.g. '2-30/2' to run on even days.
# @param renew_cron_environment
# Optional string or array of environments(s) the renewal command should have.
# E.g. PATH=/sbin:/usr/sbin:/bin:/usr/bin
#
class letsencrypt (
Boolean $configure_epel,
Expand Down Expand Up @@ -78,6 +81,7 @@
$renew_cron_hour = fqdn_rand(24),
$renew_cron_minute = fqdn_rand(60, fqdn_rand_string(10)),
$renew_cron_monthday = '*',
$renew_cron_environment = undef,
) {
if $manage_install {
contain letsencrypt::install # lint:ignore:relative_classname_inclusion
Expand Down
33 changes: 19 additions & 14 deletions manifests/renew.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@
# @param cron_monthday
# Optional string, integer or array of monthday(s) the renewal command should
# run. E.g. '2-30/2' to run on even days. Default: Every day.
# @param cron_environment
# Optional string or array of environments(s) the renewal command should have.
# E.g. PATH=/sbin:/usr/sbin:/bin:/usr/bin
#
class letsencrypt::renew (
Variant[String[1], Array[String[1]]] $pre_hook_commands = $letsencrypt::renew_pre_hook_commands,
Variant[String[1], Array[String[1]]] $post_hook_commands = $letsencrypt::renew_post_hook_commands,
Variant[String[1], Array[String[1]]] $deploy_hook_commands = $letsencrypt::renew_deploy_hook_commands,
Array[String[1]] $additional_args = $letsencrypt::renew_additional_args,
Enum['present', 'absent'] $cron_ensure = $letsencrypt::renew_cron_ensure,
Letsencrypt::Cron::Hour $cron_hour = $letsencrypt::renew_cron_hour,
Letsencrypt::Cron::Minute $cron_minute = $letsencrypt::renew_cron_minute,
Letsencrypt::Cron::Monthday $cron_monthday = $letsencrypt::renew_cron_monthday,
Variant[String[1], Array[String[1]]] $pre_hook_commands = $letsencrypt::renew_pre_hook_commands,
Variant[String[1], Array[String[1]]] $post_hook_commands = $letsencrypt::renew_post_hook_commands,
Variant[String[1], Array[String[1]]] $deploy_hook_commands = $letsencrypt::renew_deploy_hook_commands,
Array[String[1]] $additional_args = $letsencrypt::renew_additional_args,
Enum['present', 'absent'] $cron_ensure = $letsencrypt::renew_cron_ensure,
Letsencrypt::Cron::Hour $cron_hour = $letsencrypt::renew_cron_hour,
Letsencrypt::Cron::Minute $cron_minute = $letsencrypt::renew_cron_minute,
Letsencrypt::Cron::Monthday $cron_monthday = $letsencrypt::renew_cron_monthday,
Variant[String, Array[String], Undef] $cron_environment = $letsencrypt::renew_cron_environment,
) {
# Directory used for Puppet-managed renewal hooks. Make sure old unmanaged
# hooks in this directory are purged. Leave custom hooks in the default
Expand Down Expand Up @@ -77,11 +81,12 @@
$command = join($_command, ' ')

cron { 'letsencrypt-renew':
ensure => $cron_ensure,
command => $command,
user => 'root',
hour => $cron_hour,
minute => $cron_minute,
monthday => $cron_monthday,
ensure => $cron_ensure,
command => $command,
user => 'root',
hour => $cron_hour,
minute => $cron_minute,
monthday => $cron_monthday,
environment => $cron_environment,
}
}
14 changes: 14 additions & 0 deletions spec/classes/letsencrypt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@
command: 'certbot renew -q AdditionalBar')
end
end

describe 'renew_cron_ensure and environment' do
let(:additional_params) do
{ renew_cron_ensure: 'present',
renew_cron_environment: ['PATH=/usr/sbin'] }
end

it do
is_expected.to contain_cron('letsencrypt-renew').
with(ensure: 'present',
command: 'certbot renew -q',
environment: ['PATH=/usr/sbin'])
end
end
end
end

Expand Down

0 comments on commit 6da637d

Please sign in to comment.