From 5dd7a6360811b8f59bdf28a002c850cab16b3f02 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Mon, 11 Jan 2021 08:53:21 +0100 Subject: [PATCH] fix #6 Change Management Behavoir for Repositories --- README.md | 43 +++++++++++++++++++++++++++-- TESTING.md | 1 - data/RedHat/CentOS/common.yaml | 2 +- data/RedHat/OracleLinux/common.yaml | 2 +- data/RedHat/RedHat/common.yaml | 2 +- data/RedHat/Scientific/common.yaml | 2 +- data/RedHat/common.yaml | 6 ++-- data/Suse/common.yaml | 6 ++-- manifests/repos.pp | 2 +- manifests/repos/apt.pp | 13 ++++----- manifests/repos/yum.pp | 14 ++++------ manifests/repos/zypper.pp | 7 ++--- spec/classes/repos_spec.rb | 36 +++++++++++++++--------- 13 files changed, 89 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index a143081..7ee58ba 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,24 @@ 1. [Description](#description) 2. [Setup - The basics of getting started with icinga](#setup) - * [What icinga affects](#what-icinga-affects) * [Setup requirements](#setup-requirements) * [Beginning with icinga](#beginning-with-icinga) 3. [Usage - Configuration options and additional functionality](#usage) + * [Enable and disable repositories](#enable-and-disable-repositories) + * [Installing from non upstream repositories](#Installing from Non-Upstream Repositories) 4. [Reference](#reference) 5. [Release notes](#release-notes) + ## Description This module provides the management of upstrem repositories that can use by the other Icinga modules and a base class to handle the Icinga Redis package. +### Changes in v2.0.0 + +* Earlier the parameter `manage_*` enables or disables a repository but it was still managed. Now the management is enabled or disabled, see [Enable or disable repositories](#enable-and-disable-repositories). + + ## Setup ### What the Icinga Puppet module supports @@ -48,7 +55,7 @@ Add this declaration to your Puppetfile: ``` mod 'icinga', :git => 'https://github.com/icinga/puppet-icinga.git', - :tag => 'v0.1.0' + :tag => 'v2.0.0' ``` Then run: ``` @@ -62,9 +69,10 @@ git clone https://github.com/icinga/puppet-icinga.git icinga Change to `icinga` directory and check out your desired version: ``` cd icinga -git checkout v0.1.0 +git checkout v2.0.0 ``` + ## Usage By default the upstream Icinga repository for stable release are involved. @@ -95,6 +103,35 @@ class { '::icinga::repos': ``` The prefix `configure` means that the repository is not manageable by the module. But backports can be configured by the class apt::backports, that is used by this module. + +### Enable and Disable Repositories + +When manage is set to `true` for a repository the ressource is managed and the repository is enabled by default. To switch off a repository again, it still has to be managed and the corresponding parameter has to set via hiera. The module does a deep merge lookup for a hash named `icinga::repos`. Allowed keys are: + +* icinga-stable-release +* icinga-testing-builds +* icinga-snapshot-builds +* epel (only on RHEL Enterprise platforms) + +On Yum or Zypper based platforms: +``` +--- +icinga::repos: + icinga-stable-release: + enabled: 0 +``` + +Or on Apt based platforms: +``` +--- +icinga::repos: + icinga-stable-release: + ensure: absent +``` + + +### Installing from Non-Upstream Repositories + To change to a non upstream repository, e.g. a local mirror, the repos can be customized via hiera. The module does a deep merge lookup for a hash named `icinga::repos`. Allowed keys are: * icinga-stable-release diff --git a/TESTING.md b/TESTING.md index 379ddb3..bf3d920 100644 --- a/TESTING.md +++ b/TESTING.md @@ -35,7 +35,6 @@ Run unit tests: ``` cd puppet-icinga pdk test unit -pdk test unit --tests=repos ``` Or dedicated tests: diff --git a/data/RedHat/CentOS/common.yaml b/data/RedHat/CentOS/common.yaml index 1107c3e..929ad19 100644 --- a/data/RedHat/CentOS/common.yaml +++ b/data/RedHat/CentOS/common.yaml @@ -4,6 +4,6 @@ icinga::repos: descr: 'Extra Packages for Enterprise Linux %{facts.os.release.major} - $basearch' mirrorlist: 'https://mirrors.fedoraproject.org/metalink?repo=epel-%{facts.os.release.major}&arch=$basearch' baseurl: 'https://download.fedoraproject.org/pub/epel/%{facts.os.release.major}/$basearch' - enabled: 0 + enabled: 1 gpgcheck: 1 gpgkey: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-%{facts.os.release.major} diff --git a/data/RedHat/OracleLinux/common.yaml b/data/RedHat/OracleLinux/common.yaml index 1107c3e..929ad19 100644 --- a/data/RedHat/OracleLinux/common.yaml +++ b/data/RedHat/OracleLinux/common.yaml @@ -4,6 +4,6 @@ icinga::repos: descr: 'Extra Packages for Enterprise Linux %{facts.os.release.major} - $basearch' mirrorlist: 'https://mirrors.fedoraproject.org/metalink?repo=epel-%{facts.os.release.major}&arch=$basearch' baseurl: 'https://download.fedoraproject.org/pub/epel/%{facts.os.release.major}/$basearch' - enabled: 0 + enabled: 1 gpgcheck: 1 gpgkey: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-%{facts.os.release.major} diff --git a/data/RedHat/RedHat/common.yaml b/data/RedHat/RedHat/common.yaml index 1107c3e..929ad19 100644 --- a/data/RedHat/RedHat/common.yaml +++ b/data/RedHat/RedHat/common.yaml @@ -4,6 +4,6 @@ icinga::repos: descr: 'Extra Packages for Enterprise Linux %{facts.os.release.major} - $basearch' mirrorlist: 'https://mirrors.fedoraproject.org/metalink?repo=epel-%{facts.os.release.major}&arch=$basearch' baseurl: 'https://download.fedoraproject.org/pub/epel/%{facts.os.release.major}/$basearch' - enabled: 0 + enabled: 1 gpgcheck: 1 gpgkey: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-%{facts.os.release.major} diff --git a/data/RedHat/Scientific/common.yaml b/data/RedHat/Scientific/common.yaml index 1107c3e..929ad19 100644 --- a/data/RedHat/Scientific/common.yaml +++ b/data/RedHat/Scientific/common.yaml @@ -4,6 +4,6 @@ icinga::repos: descr: 'Extra Packages for Enterprise Linux %{facts.os.release.major} - $basearch' mirrorlist: 'https://mirrors.fedoraproject.org/metalink?repo=epel-%{facts.os.release.major}&arch=$basearch' baseurl: 'https://download.fedoraproject.org/pub/epel/%{facts.os.release.major}/$basearch' - enabled: 0 + enabled: 1 gpgcheck: 1 gpgkey: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-%{facts.os.release.major} diff --git a/data/RedHat/common.yaml b/data/RedHat/common.yaml index 48b81ca..123323a 100644 --- a/data/RedHat/common.yaml +++ b/data/RedHat/common.yaml @@ -3,20 +3,20 @@ icinga::repos: icinga-stable-release: descr: ICINGA (stable release for epel) baseurl: 'https://packages.icinga.com/epel/$releasever/release/' - enabled: 0 + enabled: 1 gpgcheck: 1 gpgkey: https://packages.icinga.com/icinga.key icinga-testing-builds: descr: ICINGA (testing builds for epel) baseurl: 'https://packages.icinga.com/epel/$releasever/testing/' - enabled: 0 + enabled: 1 gpgcheck: 1 gpgkey: https://packages.icinga.com/icinga.key metadata_expire: 1d icinga-snapshot-builds: descr: ICINGA (snapshot builds for epel) baseurl: 'https://packages.icinga.com/epel/$releasever/snapshot/' - enabled: 0 + enabled: 1 gpgcheck: 1 gpgkey: https://packages.icinga.com/icinga.key metadata_expire: 1d diff --git a/data/Suse/common.yaml b/data/Suse/common.yaml index 7818bd8..0b53004 100644 --- a/data/Suse/common.yaml +++ b/data/Suse/common.yaml @@ -3,18 +3,18 @@ icinga::repos: icinga-stable-release: descr: 'ICINGA (stable release for SUSE $releasever)' baseurl: 'https://packages.icinga.com/SUSE/$releasever/release/' - enabled: 0 + enabled: 1 gpgcheck: 1 gpgkey: https://packages.icinga.com/icinga.key icinga-testing-builds: descr: 'ICINGA (testing builds for SUSE $releasever)' baseurl: 'https://packages.icinga.com/SUSE/$releasever/testing/' - enabled: 0 + enabled: 1 gpgcheck: 1 gpgkey: https://packages.icinga.com/icinga.key icinga-snapshot-builds: descr: 'ICINGA (snapshot builds for SUSE $releasever)' baseurl: 'https://packages.icinga.com/SUSE/$releasever/snapshot/' - enabled: 0 + enabled: 1 gpgcheck: 1 gpgkey: https://packages.icinga.com/icinga.key diff --git a/manifests/repos.pp b/manifests/repos.pp index 60ab173..8d60ff7 100644 --- a/manifests/repos.pp +++ b/manifests/repos.pp @@ -33,7 +33,7 @@ ) { $list = lookup('icinga::repos', Hash, 'deep', {}) - $enabled = { + $managed = { icinga-stable-release => $manage_stable, icinga-testing-builds => $manage_testing, icinga-snapshot-builds => $manage_nightly, diff --git a/manifests/repos/apt.pp b/manifests/repos/apt.pp index 0085552..ec330c5 100644 --- a/manifests/repos/apt.pp +++ b/manifests/repos/apt.pp @@ -8,7 +8,7 @@ assert_private() $repos = $::icinga::repos::list - $enabled = $::icinga::repos::enabled + $managed = $::icinga::repos::managed $configure_backports = $::icinga::repos::configure_backports @@ -19,13 +19,12 @@ } $repos.each |String $repo_name, Hash $repo_config| { - apt::source { $repo_name: - * => merge($repo_config, { ensure => $enabled[$repo_name] ? { - true => present, - default => absent, - } }), + if $managed[$repo_name] { + apt::source { $repo_name: + * => merge({ ensure => present }, $repo_config), + } + Apt::Source[$repo_name] -> Package <| |> } - Apt::Source[$repo_name] -> Package <| |> } } diff --git a/manifests/repos/yum.pp b/manifests/repos/yum.pp index d8fb0d8..28cb826 100644 --- a/manifests/repos/yum.pp +++ b/manifests/repos/yum.pp @@ -8,22 +8,20 @@ assert_private() $repos = $::icinga::repos::list - $enabled = $::icinga::repos::enabled + $managed = $::icinga::repos::managed - $manage_epel = $::icinga::repos::manage_epel - - # EPEL package - if !'epel' in keys($repos) and $manage_epel { + # EPEL isn't supported + if !'epel' in keys($repos) and $managed['epel'] { warning("Repository EPEL isn't available on ${facts['os']['name']} ${facts['os']['release']['major']}.") } $repos.each |String $repo_name, Hash $repo_config| { - if $repo_name in keys($enabled) { + if $repo_name in keys($managed) and $managed[$repo_name] { yumrepo { $repo_name: - * => merge($repo_config, { enabled => Integer($enabled[$repo_name]) }) + * => $repo_config, } + Yumrepo[$repo_name] -> Package <| |> } - Yumrepo[$repo_name] -> Package <| |> } } diff --git a/manifests/repos/zypper.pp b/manifests/repos/zypper.pp index fcd2906..bfee255 100644 --- a/manifests/repos/zypper.pp +++ b/manifests/repos/zypper.pp @@ -8,17 +8,16 @@ assert_private() $repos = $::icinga::repos::list - $enabled = $::icinga::repos::enabled + $managed = $::icinga::repos::managed $repos.each |String $repo_name, Hash $repo_config| { - if $repo_name in keys($enabled) { + if $repo_name in keys($managed) and $managed[$repo_name] { if $repo_config['proxy'] { $_proxy = "--httpproxy ${repo_config['proxy']}" } else { $_proxy = undef } - exec { "import ${repo_name} gpg key": path => '/bin:/usr/bin:/sbin:/usr/sbin', command => "rpm ${_proxy} --import ${repo_config['gpgkey']}", @@ -27,7 +26,7 @@ } -> zypprepo { $repo_name: - * => merge(delete($repo_config, 'proxy'), { enabled => Integer($enabled[$repo_name]) }), + * => delete($repo_config, 'proxy') } -> file_line { "add proxy settings to ${repo_name}": diff --git a/spec/classes/repos_spec.rb b/spec/classes/repos_spec.rb index 7b7ba5e..2d04a85 100644 --- a/spec/classes/repos_spec.rb +++ b/spec/classes/repos_spec.rb @@ -13,8 +13,8 @@ case os_facts[:osfamily] when 'Debian' it { is_expected.to contain_apt__source('icinga-stable-release').with('ensure' => 'present') } - it { is_expected.to contain_apt__source('icinga-testing-builds').with('ensure' => 'absent') } - it { is_expected.to contain_apt__source('icinga-snapshot-builds').with('ensure' => 'absent') } + it { is_expected.not_to contain_apt__source('icinga-testing-builds') } + it { is_expected.not_to contain_apt__source('icinga-snapshot-builds') } case os_facts[:operatingsystem] == 'Debian' when 'Debian' @@ -33,8 +33,8 @@ when 'RedHat' it { is_expected.to contain_yumrepo('icinga-stable-release').with('enabled' => 1) } - it { is_expected.to contain_yumrepo('icinga-testing-builds').with('enabled' => 0) } - it { is_expected.to contain_yumrepo('icinga-snapshot-builds').with('enabled' => 0) } + it { is_expected.not_to contain_yumrepo('icinga-testing-builds') } + it { is_expected.not_to contain_yumrepo('icinga-snapshot-builds') } case os_facts[:operatingsystem] when 'Fedora' it { is_expected.not_to contain_yumrepo('epel') } @@ -42,14 +42,14 @@ if Integer(os_facts[:operatingsystemmajrelease]) < 8 it { is_expected.to contain_yumrepo('epel').with('enabled' => 1) } else - it { is_expected.to contain_yumrepo('epel').with('enabled' => 0) } + it { is_expected.not_to contain_yumrepo('epel') } end end when 'Suse' it { is_expected.to contain_zypprepo('icinga-stable-release').with('enabled' => 1) } - it { is_expected.to contain_zypprepo('icinga-testing-builds').with('enabled' => 0) } - it { is_expected.to contain_zypprepo('icinga-snapshot-builds').with('enabled' => 0) } + it { is_expected.not_to contain_zypprepo('icinga-testing-builds') } + it { is_expected.not_to contain_zypprepo('icinga-snapshot-builds') } end end @@ -58,13 +58,13 @@ case os_facts[:osfamily] when 'Debian' - it { is_expected.to contain_apt__source('icinga-stable-release').with('ensure' => 'absent') } + it { is_expected.not_to contain_apt__source('icinga-stable-release') } it { is_expected.to contain_apt__source('icinga-testing-builds').with('ensure' => 'present') } when 'RedHat' - it { is_expected.to contain_yumrepo('icinga-stable-release').with('enabled' => 0) } + it { is_expected.not_to contain_yumrepo('icinga-stable-release') } it { is_expected.to contain_yumrepo('icinga-testing-builds').with('enabled' => 1) } when 'Suse' - it { is_expected.to contain_zypprepo('icinga-stable-release').with('enabled' => 0) } + it { is_expected.not_to contain_zypprepo('icinga-stable-release') } it { is_expected.to contain_zypprepo('icinga-testing-builds').with('enabled' => 1) } end end @@ -74,19 +74,24 @@ case os_facts[:osfamily] when 'Debian' - it { is_expected.to contain_apt__source('icinga-stable-release').with('ensure' => 'absent') } + it { is_expected.not_to contain_apt__source('icinga-stable-release') } it { is_expected.to contain_apt__source('icinga-snapshot-builds').with('ensure' => 'present') } when 'RedHat' - it { is_expected.to contain_yumrepo('icinga-stable-release').with('enabled' => 0) } + it { is_expected.not_to contain_yumrepo('icinga-stable-release') } it { is_expected.to contain_yumrepo('icinga-snapshot-builds').with('enabled' => 1) } when 'Suse' - it { is_expected.to contain_zypprepo('icinga-stable-release').with('enabled' => 0) } + it { is_expected.not_to contain_zypprepo('icinga-stable-release') } it { is_expected.to contain_zypprepo('icinga-snapshot-builds').with('enabled' => 1) } end end case os_facts[:osfamily] when 'RedHat' + context 'with manage_epel => false' do + let(:params) { { manage_epel: false } } + + it { is_expected.not_to contain_yumrepo('epel') } + end context 'with manage_epel => true' do let(:params) { { manage_epel: true } } @@ -98,6 +103,11 @@ end end when 'Debian' + context 'with configure_backports => false' do + let(:params) { { configure_backports: false } } + + it { is_expected.not_to contain_class('apt::backports') } + end context 'with configure_backports => true' do let(:params) { { configure_backports: true } }