From ee135d60bfd6857442cab8c45caacef1919b5f10 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 27 Sep 2024 09:23:29 +0200 Subject: [PATCH] Add Debian OS family support --- .fixtures.yml | 1 + REFERENCE.md | 6 +++--- manifests/init.pp | 33 ++++++++++++++++++++------------- metadata.json | 18 ++++++++++++++++++ spec/classes/init_spec.rb | 15 +++++++++++---- 5 files changed, 53 insertions(+), 20 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index d07a6c7..6e6f78e 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -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 diff --git a/REFERENCE.md b/REFERENCE.md index f4ee9c6..e9a14c9 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -77,7 +77,7 @@ 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/'` ##### `release_package` @@ -85,7 +85,7 @@ 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"` ##### `gpgkey` @@ -93,7 +93,7 @@ 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'` ##### `use_release_package` diff --git a/manifests/init.pp b/manifests/init.pp index 1616c51..665a4ec 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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', + 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 = 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 ? { @@ -55,14 +55,21 @@ 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', + } } } } diff --git a/metadata.json b/metadata.json index dd28119..ccf92ef 100644 --- a/metadata.json +++ b/metadata.json @@ -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": [ @@ -59,6 +63,20 @@ "8", "9" ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "12" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "20.04", + "22.04", + "24.04" + ] } ], "requirements": [ diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index da4ec71..4a01a93 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -3,10 +3,10 @@ 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 @@ -14,6 +14,7 @@ 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.not_to contain_apt__source('puppet-tools-release') } end context 'with use_release_package=false' do @@ -22,10 +23,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, @@ -45,6 +51,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