Skip to content

Commit

Permalink
Merge pull request #240 from alexskr/fix_default_su_group_ubuntu
Browse files Browse the repository at this point in the history
Add Ubuntu 20.04, 22.04, 24.04 support
  • Loading branch information
bastelfreak authored Jan 17, 2025
2 parents ac49f58 + a27370f commit e9351b4
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 20 deletions.
5 changes: 5 additions & 0 deletions data/Ubuntu.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
5 changes: 5 additions & 0 deletions data/Ubuntu/18.04.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
logrotate::ensure_cron_daily: present
logrotate::ensure_cron_hourly: present
logrotate::manage_systemd_timer: false
logrotate::ensure_systemd_timer: absent
13 changes: 8 additions & 5 deletions hiera.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ defaults:
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 - Major Release'
paths:
# Used to distinguish between Debian and Ubuntu
- "%{facts.os.name}/%{facts.os.release.major}.yaml"
- "%{facts.os.family}/%{facts.os.release.major}.yaml"
- name: 'Operating System Family'
path: "%{facts.os.family}.yaml"
paths:
- "%{facts.os.name}.yaml"
- "%{facts.os.family}.yaml"
- name: 'defaults'
path: 'defaults.yaml'
9 changes: 8 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@
'Ubuntu' => 'root',
default => undef,
}

$ubuntu_default_su_group = $facts['os']['release']['full'] ? {
'18.04' => 'syslog',
default => 'adm',
}

$default_su_group = $facts['os']['name'] ? {
'Ubuntu' => 'syslog',
'Ubuntu' => $ubuntu_default_su_group,
default => undef
}

$conf_params = {
su => $default_su,
su_user => $default_su_user,
Expand Down
5 changes: 4 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"18.04"
"18.04",
"20.04",
"22.04",
"24.04"
]
},
{
Expand Down
33 changes: 21 additions & 12 deletions spec/classes/defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,8 @@
let(:facts) { os_facts }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_logrotate__conf('/etc/logrotate.conf') }

if os_facts['os']['name'] == 'Ubuntu'
it {
is_expected.to contain_logrotate__conf('/etc/logrotate.conf').with(
'su_user' => 'root',
'su_group' => 'syslog'
)
}
else
it {
is_expected.to contain_logrotate__conf('/etc/logrotate.conf')
}
end
it {
is_expected.to contain_logrotate__rule('wtmp').with(
'rotate_every' => 'monthly',
Expand All @@ -56,6 +45,26 @@
}
end

context os, if: os_facts['os']['name'] == 'Ubuntu' do
let(:facts) { os_facts }

if os_facts['os']['release']['full'].to_i <= 18
it {
is_expected.to contain_logrotate__conf('/etc/logrotate.conf').with(
'su_user' => 'root',
'su_group' => 'syslog'
)
}
else
it {
is_expected.to contain_logrotate__conf('/etc/logrotate.conf').with(
'su_user' => 'root',
'su_group' => 'adm'
)
}
end
end

context os, if: os_facts['os']['family'] == 'RedHat' do
let(:facts) { os_facts }

Expand Down
3 changes: 2 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
is_expected.to contain_class('logrotate::defaults')
end

if os_facts['os']['family'] == 'RedHat' && os_facts['os']['release']['major'].to_i >= 9
if (os_facts['os']['family'] == 'RedHat' && os_facts['os']['release']['major'].to_i >= 9) ||
(os_facts['os']['name'] == 'Ubuntu' && os_facts['os']['release']['major'].to_i >= 20)
it do
is_expected.to contain_service('logrotate.timer').with(
'ensure' => 'running',
Expand Down

0 comments on commit e9351b4

Please sign in to comment.