Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions manifests/cron.pp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@
}
}

if $logrotate::manage_cron_subdirectories {
case $facts['os']['family'] {
'FreeBSD': {}
default: {
$cron_dir = "/etc/cron.${name}"
ensure_resources('file', { $cron_dir => {
ensure => directory,
owner => $logrotate::root_user,
group => $logrotate::root_group,
} })

File <<| name == $script_path |>> {
require => File[$cron_dir]
}
}
}
}

file { $script_path:
ensure => $ensure,
owner => $logrotate::root_user,
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
String $root_group = $logrotate::params::root_group,
Array[String[1]] $logrotate_args = [],
Boolean $cron_always_output = false,
Boolean $manage_cron_subdirectories = true,
) inherits logrotate::params {
contain logrotate::install
contain logrotate::config
Expand Down
22 changes: 22 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,28 @@
it { is_expected.to contain_file('/etc/cron.hourly/logrotate').with_ensure('absent') }
end
end

context 'with logrotate rule' do
let(:params) {{
manage_cron_hourly: true,
rules: {
nginx: {
path: ['/var/log/nginx/*.log'],
rotate_every: 'hour',
}
}
}}

case os_facts['os']['name']
when 'FreeBSD'
it { is_expected.to contain_file('/usr/local/etc/logrotate.d/hourly').with_ensure('directory') }
else
it { is_expected.to contain_file('/etc/logrotate.d/hourly').with_ensure('directory') }
it { is_expected.to contain_file('/etc/logrotate.d/hourly/nginx').with_ensure('present').with_content(%r{/var/log/nginx/\*.log\s\{\n\s+hourly\n\}}) }
it { is_expected.to contain_file('/etc/cron.hourly').with_ensure('directory') }
it { is_expected.to contain_logrotate__rule('nginx') }
end
end
end
end
end
Expand Down