Showing with 157 additions and 45 deletions.
  1. +7 −4 .github/CONTRIBUTING.md
  2. +1 −1 .msync.yml
  3. +8 −0 CHANGELOG.md
  4. +1 −1 Gemfile
  5. +18 −0 REFERENCE.md
  6. +5 −0 data/RedHat/9.yaml
  7. +16 −0 hiera.yaml
  8. +14 −0 manifests/config.pp
  9. +28 −26 manifests/init.pp
  10. +1 −1 metadata.json
  11. +30 −3 spec/classes/init_spec.rb
  12. +11 −2 spec/defines/conf_spec.rb
  13. +15 −6 spec/defines/rule_spec.rb
  14. +1 −0 spec/spec_helper.rb
  15. +1 −1 spec/spec_helper_acceptance.rb
11 changes: 7 additions & 4 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,21 @@ simple tests against it after applying the module. You can run this
with:

```sh
BEAKER_setfile=debian11-64 bundle exec rake beaker
BEAKER_PUPPET_COLLECTION=puppet7 BEAKER_setfile=debian11-64 bundle exec rake beaker
```

You can replace the string `debian10` with any common operating system.
You can replace the string `debian11` with any common operating system.
The following strings are known to work:

* ubuntu1804
* ubuntu2004
* debian10
* ubuntu2204
* debian11
* centos7
* centos8
* centos9
* almalinux8
* almalinux9
* fedora36

For more information and tips & tricks, see [voxpupuli-acceptance's documentation](https://github.com/voxpupuli/voxpupuli-acceptance#running-tests).

Expand Down
2 changes: 1 addition & 1 deletion .msync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

modulesync_config_version: '6.0.0'
modulesync_config_version: '7.0.0'
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
Each new release typically also includes the latest modulesync defaults.
These should not affect the functionality of the module.

## [v7.0.1](https://github.com/voxpupuli/puppet-logrotate/tree/v7.0.1) (2023-12-05)

[Full Changelog](https://github.com/voxpupuli/puppet-logrotate/compare/v7.0.0...v7.0.1)

**Fixed bugs:**

- Use default systemd timer for EL9 logrotate [\#216](https://github.com/voxpupuli/puppet-logrotate/pull/216) ([treydock](https://github.com/treydock))

## [v7.0.0](https://github.com/voxpupuli/puppet-logrotate/tree/v7.0.0) (2023-08-02)

[Full Changelog](https://github.com/voxpupuli/puppet-logrotate/compare/v6.1.0...v7.0.0)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
source ENV['GEM_SOURCE'] || 'https://rubygems.org'

group :test do
gem 'voxpupuli-test', '~> 6.0', :require => false
gem 'voxpupuli-test', '~> 7.0', :require => false
gem 'coveralls', :require => false
gem 'simplecov-console', :require => false
gem 'puppet_metadata', '~> 3.0', :require => false
Expand Down
18 changes: 18 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ The following parameters are available in the `logrotate` class:
* [`manage_cron_hourly`](#-logrotate--manage_cron_hourly)
* [`ensure_cron_daily`](#-logrotate--ensure_cron_daily)
* [`ensure_cron_hourly`](#-logrotate--ensure_cron_hourly)
* [`manage_systemd_timer`](#-logrotate--manage_systemd_timer)
* [`ensure_systemd_timer`](#-logrotate--ensure_systemd_timer)
* [`create_base_rules`](#-logrotate--create_base_rules)
* [`purge_configdir`](#-logrotate--purge_configdir)
* [`package`](#-logrotate--package)
Expand Down Expand Up @@ -112,6 +114,22 @@ Data type: `Enum[present,absent]`

Default value: `'present'`

##### <a name="-logrotate--manage_systemd_timer"></a>`manage_systemd_timer`

Data type: `Boolean`



Default value: `false`

##### <a name="-logrotate--ensure_systemd_timer"></a>`ensure_systemd_timer`

Data type: `Enum[present,absent]`



Default value: `'absent'`

##### <a name="-logrotate--create_base_rules"></a>`create_base_rules`

Data type: `Boolean`
Expand Down
5 changes: 5 additions & 0 deletions data/RedHat/9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
logrotate::ensure_cron_daily: absent
logrotate::ensure_cron_hourly: absent
logrotate::manage_systemd_timer: true
logrotate::ensure_systemd_timer: present
16 changes: 16 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
version: 5

defaults:
datadir: 'data'
data_hash: yaml_data

hierarchy:
- name: 'Distribution Name'
path: "%{facts.os.name}.yaml"
- name: 'Operating System Family - Major version'
path: "%{facts.os.family}/%{facts.os.release.major}.yaml"
- name: 'Operating System Family'
path: "%{facts.os.family}.yaml"
- name: 'defaults'
path: 'defaults.yaml'
14 changes: 14 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@
}
}

if $logrotate::manage_systemd_timer {
if $logrotate::ensure_systemd_timer == 'present' {
service { 'logrotate.timer':
ensure => 'running',
enable => true,
}
} else {
service { 'logrotate.timer':
ensure => 'stopped',
enable => false,
}
}
}

if $logrotate::config {
logrotate::conf { $logrotate::logrotate_conf:
* => $logrotate::config,
Expand Down
54 changes: 28 additions & 26 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
#
class logrotate (
String $ensure = present,
Boolean $hieramerge = false,
Boolean $manage_cron_daily = true,
Boolean $manage_cron_hourly = true,
Enum[present,absent] $ensure_cron_daily = 'present',
Enum[present,absent] $ensure_cron_hourly = 'present',
Boolean $create_base_rules = true,
Boolean $purge_configdir = false,
String $package = 'logrotate',
Hash $rules = {},
Optional[Hash] $config = undef,
Integer[0,23] $cron_daily_hour = $logrotate::params::cron_daily_hour,
Integer[0,59] $cron_daily_minute = $logrotate::params::cron_daily_minute,
Integer[0,59] $cron_hourly_minute = $logrotate::params::cron_hourly_minute,
Stdlib::Filemode $cron_file_mode = $logrotate::params::cron_file_mode,
String $configdir = $logrotate::params::configdir,
String $logrotate_bin = $logrotate::params::logrotate_bin,
String $logrotate_conf = $logrotate::params::logrotate_conf,
Stdlib::Filemode $logrotate_conf_mode = $logrotate::params::logrotate_conf_mode,
Boolean $manage_package = $logrotate::params::manage_package,
String $rules_configdir = $logrotate::params::rules_configdir,
Stdlib::Filemode $rules_configdir_mode = $logrotate::params::rules_configdir_mode,
String $root_user = $logrotate::params::root_user,
String $root_group = $logrotate::params::root_group,
Array[String[1]] $logrotate_args = [],
Boolean $cron_always_output = false,
String $ensure = present,
Boolean $hieramerge = false,
Boolean $manage_cron_daily = true,
Boolean $manage_cron_hourly = true,
Enum[present,absent] $ensure_cron_daily = 'present',
Enum[present,absent] $ensure_cron_hourly = 'present',
Boolean $manage_systemd_timer = false,
Enum[present,absent] $ensure_systemd_timer = 'absent',
Boolean $create_base_rules = true,
Boolean $purge_configdir = false,
String $package = 'logrotate',
Hash $rules = {},
Optional[Hash] $config = undef,
Integer[0,23] $cron_daily_hour = $logrotate::params::cron_daily_hour,
Integer[0,59] $cron_daily_minute = $logrotate::params::cron_daily_minute,
Integer[0,59] $cron_hourly_minute = $logrotate::params::cron_hourly_minute,
Stdlib::Filemode $cron_file_mode = $logrotate::params::cron_file_mode,
String $configdir = $logrotate::params::configdir,
String $logrotate_bin = $logrotate::params::logrotate_bin,
String $logrotate_conf = $logrotate::params::logrotate_conf,
Stdlib::Filemode $logrotate_conf_mode = $logrotate::params::logrotate_conf_mode,
Boolean $manage_package = $logrotate::params::manage_package,
String $rules_configdir = $logrotate::params::rules_configdir,
Stdlib::Filemode $rules_configdir_mode = $logrotate::params::rules_configdir_mode,
String $root_user = $logrotate::params::root_user,
String $root_group = $logrotate::params::root_group,
Array[String[1]] $logrotate_args = [],
Boolean $cron_always_output = false,
) inherits logrotate::params {
contain logrotate::install
contain logrotate::config
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppet-logrotate",
"version": "7.0.0",
"version": "7.0.1",
"author": "Vox Pupuli",
"summary": "Manage logrotate",
"license": "MIT",
Expand Down
33 changes: 30 additions & 3 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
let(:facts) do
facts
end
let(:cron_ensure) do
if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'].to_i >= 9
'absent'
else
'present'
end
end
let(:hourly_dir_ensure) do
if cron_ensure == 'present'
'directory'
else
'absent'
end
end

context 'logrotate class without any parameters' do
it { is_expected.to compile.with_all_deps }
Expand Down Expand Up @@ -42,7 +56,7 @@
else
it do
is_expected.to contain_file('/etc/logrotate.d/hourly').with(
'ensure' => 'directory',
'ensure' => hourly_dir_ensure,
'owner' => 'root',
'group' => 'root',
'mode' => '0755'
Expand All @@ -51,7 +65,7 @@

it do
is_expected.to contain_file('/etc/cron.hourly/logrotate').with(
'ensure' => 'present',
'ensure' => cron_ensure,
'owner' => 'root',
'group' => 'root',
'mode' => '0700'
Expand All @@ -66,13 +80,26 @@
'group' => 'root',
'mode' => '0755')

is_expected.to contain_file('/etc/cron.daily/logrotate').with('ensure' => 'present',
is_expected.to contain_file('/etc/cron.daily/logrotate').with('ensure' => cron_ensure,
'owner' => 'root',
'group' => 'root',
'mode' => '0700')

is_expected.to contain_class('logrotate::defaults')
end

if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'].to_i >= 9
it do
is_expected.to contain_service('logrotate.timer').with(
'ensure' => 'running',
'enable' => true
)
end
else
it do
is_expected.not_to contain_service('logrotate.timer')
end
end
end
end

Expand Down
13 changes: 11 additions & 2 deletions spec/defines/conf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
require 'spec_helper'

describe 'logrotate::conf' do
_, facts = on_supported_os.first
_, facts = on_supported_os(
{
supported_os: [
{
'operatingsystem' => 'RedHat',
'operatingsystemrelease' => ['8'],
}
]
}
).first
let(:facts) { facts }

shared_examples 'error raised' do |param, _os|
Expand Down Expand Up @@ -300,7 +309,7 @@
let(:params) { { dateformat: '-%Y%m%d' } }

it {
is_expected.to contain_file('/etc/logrotate.conf').\
is_expected.to contain_file('/etc/logrotate.conf'). \
with_content(%r{^dateformat -%Y%m%d$})
}
end
Expand Down
21 changes: 15 additions & 6 deletions spec/defines/rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
require 'shared_examples'

describe 'logrotate::rule' do
_, facts = on_supported_os.first
_, facts = on_supported_os(
{
supported_os: [
{
'operatingsystem' => 'RedHat',
'operatingsystemrelease' => ['8'],
}
]
}
).first
let(:facts) { facts }

context 'ensure => absent' do
Expand Down Expand Up @@ -175,7 +184,7 @@
let(:params) { { path: '/var/log/foo.log', create: false } }

it do
is_expected.to contain_file('/etc/logrotate.d/test').\
is_expected.to contain_file('/etc/logrotate.d/test'). \
with_content(%r{^ nocreate$})
end

Expand All @@ -202,7 +211,7 @@
let(:params) { { path: '/var/log/foo.log', custom_cfg: ['hourly'] } }

it {
is_expected.to contain_file('/etc/logrotate.d/test').\
is_expected.to contain_file('/etc/logrotate.d/test'). \
with_content(%r{^ hourly$})
}
end
Expand All @@ -213,7 +222,7 @@
let(:params) { { path: '/var/log/foo.log', dateformat: '-%Y%m%d' } }

it {
is_expected.to contain_file('/etc/logrotate.d/test').\
is_expected.to contain_file('/etc/logrotate.d/test'). \
with_content(%r{^ dateformat -%Y%m%d$})
}
end
Expand Down Expand Up @@ -384,7 +393,7 @@
let(:params) { { path: '/var/log/foo.log', lastaction: ['/bin/true', '/bin/false'] } }

it {
is_expected.to contain_file('/etc/logrotate.d/test').\
is_expected.to contain_file('/etc/logrotate.d/test'). \
with_content(%r{lastaction\n /bin/true\n /bin/false\n endscript})
}
end
Expand All @@ -395,7 +404,7 @@
let(:params) { { path: '/var/log/foo.log', rotate: 3 } }

it {
is_expected.to contain_file('/etc/logrotate.d/test').\
is_expected.to contain_file('/etc/logrotate.d/test'). \
with_content(%r{^ rotate 3$})
}
end
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
add_custom_fact name.to_sym, value
end
end
Dir['./spec/support/spec/**/*.rb'].sort.each { |f| require f }
2 changes: 1 addition & 1 deletion spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

require 'voxpupuli/acceptance/spec_helper_acceptance'

configure_beaker
configure_beaker(modules: :metadata)

Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f }