Skip to content

Commit

Permalink
add parameter $environment to defined type ds_389::backup
Browse files Browse the repository at this point in the history
This should fix a "command not found" error in the default backup job
that is caused by a missing PATH variable.
  • Loading branch information
fraenki committed Nov 30, 2020
1 parent bb17d3a commit 34ea4a0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
* Add parameter `$environment` to defined type `ds_389::backup`

### Changed
* Add PATH environment variable to default backup cron job

### Fixed
* Fix "command not found" error in backup cron job due to missing PATH variable

## [2.3.0] - 2020-11-18

### Added
Expand Down
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,15 @@ or removed (`absent`).

Default value: `'present'`

##### `environment`

Data type: `Array`

Any environment settings associated with the backup cron job. Note that the
PATH variable is automatically added to the environment.

Default value: `[]`

##### `root_dn_pass`

Data type: `Variant[String,Sensitive[String]]`
Expand Down
25 changes: 19 additions & 6 deletions manifests/backup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# This parameter controls whether the backup job should be created (`present`)
# or removed (`absent`).
#
# @param environment
# Any environment settings associated with the backup cron job. Note that the
# PATH variable is automatically added to the environment.
#
# @param root_dn_pass
# The password to use when performing the backup. Required.
#
Expand Down Expand Up @@ -44,6 +48,7 @@
Variant[String,Sensitive[String]] $root_dn_pass,
String $server_id,
String $ensure = 'present',
Array $environment = [],
Enum['ldap','ldaps'] $protocol = 'ldaps',
Integer $rotate = 30,
Array $time = ['15', '23', '*'],
Expand Down Expand Up @@ -84,6 +89,13 @@
show_diff => false,
}

# Set environment variables for the cron job.
if ($environment) {
$_environment = $environment + ["PATH=${ds_389::path}"]
} else {
$_environment = ["PATH=${ds_389::path}"]
}

# Command to perform all backup and cleanup tasks.
$backup_command = join([
# Create tasks to perform the backup.
Expand All @@ -101,11 +113,12 @@
], ' ')

cron { "Backup job for ${server_id}: ${name}":
ensure => $ensure,
command => $backup_command,
user => $ds_389::user,
minute => $time[0],
hour => $time[1],
weekday => $time[2],
ensure => $ensure,
command => $backup_command,
user => $ds_389::user,
environment => $_environment,
minute => $time[0],
hour => $time[1],
weekday => $time[2],
}
}
3 changes: 3 additions & 0 deletions spec/defines/backup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
it {
is_expected.to contain_cron('Backup job for specdirectory: specbackup').with(
command: "dsconf -D 'cn=Directory Manager' -y '/etc/dirsrv/slapd-specdirectory/backup_passwd.specbackup' ldaps://foo.example.com:636 backup create && touch /tmp/389ds_backup_success && find '/var/lib/dirsrv/slapd-specdirectory/bak/' -mindepth 1 -maxdepth 1 -mtime +30 -print0 | xargs -0 -r rm -rf", # rubocop:disable LineLength
environment: ["PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"],
user: 'dirsrv',
minute: '15',
hour: '23',
Expand Down Expand Up @@ -90,6 +91,7 @@
root_dn: 'cn=Directory Manager',
root_dn_pass: 'supersecret',
backup_dir: '/path/to/ds-backups',
environment: ['[email protected]'],
protocol: 'ldap',
rotate: 10,
server_host: 'ldap.test.org',
Expand All @@ -116,6 +118,7 @@
it {
is_expected.to contain_cron('Backup job for specdirectory: specbackup').with(
command: "dsconf -D 'cn=Directory Manager' -y '/etc/dirsrv/slapd-specdirectory/backup_passwd.specbackup' ldap://ldap.test.org:1389 backup create /path/to/ds-backups && touch /tmp/hourly_backup_success && find '/path/to/ds-backups/' -mindepth 1 -maxdepth 1 -mtime +10 -print0 | xargs -0 -r rm -rf", # rubocop:disable LineLength
environment: ["[email protected]","PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"],
user: 'dirsrv',
minute: '0',
hour: '*',
Expand Down

0 comments on commit 34ea4a0

Please sign in to comment.