diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a72015..3137722 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/REFERENCE.md b/REFERENCE.md index 4a4cdf8..7c0ee6d 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -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]]` diff --git a/manifests/backup.pp b/manifests/backup.pp index 8646102..5de320d 100644 --- a/manifests/backup.pp +++ b/manifests/backup.pp @@ -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. # @@ -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', '*'], @@ -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. @@ -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], } } diff --git a/spec/defines/backup_spec.rb b/spec/defines/backup_spec.rb index 2814792..0e21a06 100644 --- a/spec/defines/backup_spec.rb +++ b/spec/defines/backup_spec.rb @@ -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', @@ -90,6 +91,7 @@ root_dn: 'cn=Directory Manager', root_dn_pass: 'supersecret', backup_dir: '/path/to/ds-backups', + environment: ['MAILTO=admin@example.com'], protocol: 'ldap', rotate: 10, server_host: 'ldap.test.org', @@ -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: ["MAILTO=admin@example.com","PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"], user: 'dirsrv', minute: '0', hour: '*',