Skip to content

Commit

Permalink
Add Debian OS family support
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Sep 27, 2024
1 parent 86351c0 commit 819f9ff
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 24 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
fixtures:
repositories:
apt: https://github.com/puppetlabs/puppetlabs-apt.git
stdlib: https://github.com/puppetlabs/puppetlabs-stdlib.git
sudo: https://github.com/saz/puppet-sudo.git
systemd: https://github.com/voxpupuli/puppet-systemd.git
Expand Down
8 changes: 4 additions & 4 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,31 @@ Data type: `Stdlib::HTTPSUrl`

HTTPS URL to the yumrepo base

Default value: `'https://yum.puppet.com/'`
Default value: `$facts['os']['family'] ? { 'Debian' => 'https://apt.puppet.com/', 'RedHat' => 'https://yum.puppet.com/'`

##### <a name="-bolt--release_package"></a>`release_package`

Data type: `String[1]`

filename for the release package rpm

Default value: `"puppet-tools-release-el-${facts['os']['release']['major']}.noarch.rpm"`
Default value: `$facts['os']['family'] ? { 'Debian' => "puppet-release-${fact('os.distro.codename')}.deb", 'RedHat' => "puppet-tools-release-el-${facts['os']['release']['major']}.noarch.rpm"`

##### <a name="-bolt--gpgkey"></a>`gpgkey`

Data type: `String[1]`

name of the GPG key filename in the repo

Default value: `'RPM-GPG-KEY-puppet-20250406'`
Default value: `$facts['os']['family'] ? { 'Debian' => 'DEB-GPG-KEY-puppet-20250406', 'RedHat' => 'RPM-GPG-KEY-puppet-20250406'`

##### <a name="-bolt--use_release_package"></a>`use_release_package`

Data type: `Boolean`

enable/disable the puppet-tools-release package installation. When disabled, we will configure the repo as yumrepo resource

Default value: `true`
Default value: `$facts['os']['family'] ? { 'Debian' => false, 'RedHat' => true`

##### <a name="-bolt--yumrepo_base_url"></a>`yumrepo_base_url`

Expand Down
36 changes: 22 additions & 14 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
#
class bolt (
String[1] $version = 'installed',
Stdlib::HTTPSUrl $base_url = 'https://yum.puppet.com/',
String[1] $release_package = "puppet-tools-release-el-${facts['os']['release']['major']}.noarch.rpm",
String[1] $gpgkey = 'RPM-GPG-KEY-puppet-20250406',
Boolean $use_release_package = true,
Stdlib::HTTPSUrl $base_url = $facts['os']['family'] ? { 'Debian' => 'https://apt.puppet.com/', 'RedHat' => 'https://yum.puppet.com/', },
String[1] $release_package = $facts['os']['family'] ? { 'Debian' => "puppet-release-${fact('os.distro.codename')}.deb", 'RedHat' => "puppet-tools-release-el-${facts['os']['release']['major']}.noarch.rpm", },
String[1] $gpgkey = $facts['os']['family'] ? { 'Debian' => 'DEB-GPG-KEY-puppet-20250406', 'RedHat' => 'RPM-GPG-KEY-puppet-20250406', },
Boolean $use_release_package = $facts['os']['family'] ? { 'Debian' => false, 'RedHat' => true, },
Stdlib::HTTPSUrl $yumrepo_base_url = "${base_url}puppet-tools/el/${facts['os']['release']['major']}/\$basearch",
Boolean $manage_repo = true,
) {
unless $facts['os']['family'] == 'RedHat' {
fail('class bolt only works on RedHat OS family')
unless $facts['os']['family'] in ['RedHat', 'Debian'] {
fail("class bolt only works on ${facts['os']['family']} OS family")
}

$ensure = $version ? {
Expand All @@ -55,14 +55,22 @@
before => Package['puppet-bolt'],
}
} else {
yumrepo { 'puppet-tools':
ensure => $ensure,
baseurl => $yumrepo_base_url,
descr => "Puppet Tools Repository el ${facts['os']['release']['major']} - \$basearch",
enabled => '1',
gpgcheck => '1',
gpgkey => "${base_url}${gpgkey}",
before => Package['puppet-bolt'],
if $facts['os']['family'] == 'RedHat' {
yumrepo { 'puppet-tools':
ensure => $ensure,
baseurl => $yumrepo_base_url,
descr => "Puppet Tools Repository el ${facts['os']['release']['major']} - \$basearch",
enabled => '1',
gpgcheck => '1',
gpgkey => "${base_url}${gpgkey}",
before => Package['puppet-bolt'],
}
} else {
apt::source { 'puppet-tools-release':
location => $base_url,
repos => 'puppet-tools',
before => Package['puppet-bolt'],
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
{
"name": "saz/sudo",
"version_requirement": ">= 8.0.0 < 9.0.0"
},
{
"name": "puppetlabs/apt",
"version_requirement": ">= 9.4.0 < 10.0.0"
}
],
"operatingsystem_support": [
Expand Down Expand Up @@ -59,6 +63,14 @@
"8",
"9"
]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"20.04",
"22.04",
"24.04"
]
}
],
"requirements": [
Expand Down
22 changes: 17 additions & 5 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
require 'spec_helper'

describe 'bolt' do
on_supported_os.each do |os, facts|
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let :facts do
facts
os_facts
end

context 'with all defaults' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('puppet-bolt') }
it { is_expected.to contain_package('puppet-tools-release') }
it { is_expected.not_to contain_yumrepo('puppet-tools') }

Check failure on line 15 in spec/classes/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

RSpec/EmptyLineAfterExample: Add an empty line after `it`. (https://rspec.rubystyle.guide/#empty-lines-around-examples, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterExample)
if os_facts['os']['family'] == 'RedHat'
it { is_expected.to contain_package('puppet-tools-release') }
it { is_expected.not_to contain_apt__source('puppet-tools-release') }
else
it { is_expected.not_to contain_package('puppet-tools-release') }
it { is_expected.to contain_apt__source('puppet-tools-release') }
end
end

context 'with use_release_package=false' do
Expand All @@ -22,10 +28,15 @@
end

it { is_expected.not_to contain_package('puppet-tools-release') }
it { is_expected.to contain_yumrepo('puppet-tools') }

if os_facts['os']['family'] == 'RedHat'
it { is_expected.to contain_yumrepo('puppet-tools') }
else
it { is_expected.to contain_apt__source('puppet-tools-release') }
end
end

context 'with use_release_package=false and odd mirrors' do
context 'with use_release_package=false and odd mirrors', if: os_facts['os']['family'] == 'RedHat' do
let :params do
{
use_release_package: false,
Expand All @@ -45,6 +56,7 @@

it { is_expected.not_to contain_package('puppet-tools-release') }
it { is_expected.not_to contain_yumrepo('puppet-tools') }
it { is_expected.not_to contain_apt__source('puppet-tools-release') }
end
end
end
Expand Down
9 changes: 8 additions & 1 deletion spec/defines/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@
it { is_expected.to contain_user(title) }
it { is_expected.to contain_group(title) }
it { is_expected.to contain_package('puppet-bolt') }
it { is_expected.to contain_package('puppet-tools-release') }
it { is_expected.not_to contain_yumrepo('puppet-tools') }
it { is_expected.to contain_sudo__conf(title) }
it { is_expected.to contain_systemd__unit_file("#{title}@.service") }

if os_facts['os']['family'] == 'RedHat'
it { is_expected.to contain_package('puppet-tools-release') }
it { is_expected.not_to contain_apt__source('puppet-tools-release') }
else
it { is_expected.not_to contain_package('puppet-tools-release') }
it { is_expected.to contain_apt__source('puppet-tools-release') }
end
end
end

Expand Down

0 comments on commit 819f9ff

Please sign in to comment.