Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Debian OS family support #35

Merged
merged 1 commit into from
Sep 27, 2024
Merged
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
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/', },
rwaffen marked this conversation as resolved.
Show resolved Hide resolved
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
11 changes: 11 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,13 @@
"8",
"9"
]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"20.04",
"22.04"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

]
}
],
"requirements": [
Expand Down
9 changes: 7 additions & 2 deletions spec/acceptance/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class { 'bolt':

describe 'packages' do
it { expect(package('puppet-bolt')).to be_installed }
it { expect(package('puppet-tools-release')).to be_installed }
end
end

Expand All @@ -71,8 +70,14 @@ class { 'bolt':
it { expect(package('puppet-tools-release')).not_to be_installed }
end

describe 'file' do
describe 'yum file', if: fact('os.family') == 'RedHat' do
it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) }
it { expect(file('/etc/apt/sources.list.d/puppet-tools-release.list')).to be_missing.or(have_attributes(size: 0)) }
end

describe 'apt file', if: fact('os.family') != 'RedHat' do
it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) }
it { expect(file('/etc/apt/sources.list.d/puppet-tools-release.list')).to be_file }
end
end
end
7 changes: 7 additions & 0 deletions spec/acceptance/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@
describe package('puppet-bolt') do
it { is_expected.to be_installed }
end

describe 'file' do
it { expect(file('/opt/peadmmig/inventory.yaml')).to be_file }
it { expect(file('/opt/peadmmig/bolt-project.yaml')).to be_file }
it { expect(file('/etc/systemd/system/[email protected]')).to be_file }
it { expect(file('/etc/sudoers.d/10_peadmmig')).to be_file }
end
end
end
23 changes: 18 additions & 5 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
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') }

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 +29,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 +57,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