Skip to content

Commit

Permalink
fix #6 Change Management Behavoir for Repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
lbetz committed Jan 11, 2021
1 parent 7cbc225 commit 5dd7a63
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 47 deletions.
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
```
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Run unit tests:
```
cd puppet-icinga
pdk test unit
pdk test unit --tests=repos
```

Or dedicated tests:
Expand Down
2 changes: 1 addition & 1 deletion data/RedHat/CentOS/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
2 changes: 1 addition & 1 deletion data/RedHat/OracleLinux/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
2 changes: 1 addition & 1 deletion data/RedHat/RedHat/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
2 changes: 1 addition & 1 deletion data/RedHat/Scientific/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
6 changes: 3 additions & 3 deletions data/RedHat/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions data/Suse/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion manifests/repos.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 6 additions & 7 deletions manifests/repos/apt.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
assert_private()

$repos = $::icinga::repos::list
$enabled = $::icinga::repos::enabled
$managed = $::icinga::repos::managed

$configure_backports = $::icinga::repos::configure_backports

Expand All @@ -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 <| |>
}

}
14 changes: 6 additions & 8 deletions manifests/repos/yum.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <| |>
}

}
Expand Down
7 changes: 3 additions & 4 deletions manifests/repos/zypper.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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']}",
Expand All @@ -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}":
Expand Down
36 changes: 23 additions & 13 deletions spec/classes/repos_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -33,23 +33,23 @@

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') }
else
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

Expand All @@ -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
Expand All @@ -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 } }

Expand All @@ -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 } }

Expand Down

0 comments on commit 5dd7a63

Please sign in to comment.