From 6fe7265ee662e15c4c4dafb9180d3b5f88fbc8ee Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Sun, 3 Feb 2019 16:59:25 +0100 Subject: [PATCH] fix #519 Remove repos info to data in module hiera --- data/Debian-family.yaml | 7 ++++ data/Fedora.yaml | 3 ++ data/OpenSuSE.yaml | 3 ++ data/RedHat-family.yaml | 6 +++ data/Suse-family.yaml | 5 +++ data/Ubuntu.yaml | 3 ++ hiera.yaml | 3 ++ manifests/repo.pp | 86 ++++++++++------------------------------- 8 files changed, 50 insertions(+), 66 deletions(-) create mode 100644 data/Fedora.yaml create mode 100644 data/OpenSuSE.yaml create mode 100644 data/Ubuntu.yaml diff --git a/data/Debian-family.yaml b/data/Debian-family.yaml index c25a56b05..60aa2389d 100644 --- a/data/Debian-family.yaml +++ b/data/Debian-family.yaml @@ -2,3 +2,10 @@ icinga2::globals::user: nagios icinga2::globals::group: nagios icinga2::globals::icinga2_bin: /usr/sbin/icinga2 +icinga2::repo: + location: http://packages.icinga.com/debian + release: 'icinga-%{facts.os.distro.codename}' + repos: main + key: + id: F51A91A5EE001AA5D77D53C4C6E319C334410682 + source: http://packages.icinga.com/icinga.key diff --git a/data/Fedora.yaml b/data/Fedora.yaml new file mode 100644 index 000000000..efbde8a5c --- /dev/null +++ b/data/Fedora.yaml @@ -0,0 +1,3 @@ +--- +icinga2::repo: + baseurl: 'http://packages.icinga.com/fedora/%{facts.os.release.major}/release/' diff --git a/data/OpenSuSE.yaml b/data/OpenSuSE.yaml new file mode 100644 index 000000000..1d3a5cda4 --- /dev/null +++ b/data/OpenSuSE.yaml @@ -0,0 +1,3 @@ +--- +icinga2::repo: + baseurl: 'http://packages.icinga.com/openSUSE/%{facts.os.release.full}/release/' diff --git a/data/RedHat-family.yaml b/data/RedHat-family.yaml index d7416ee6a..370ca34a8 100644 --- a/data/RedHat-family.yaml +++ b/data/RedHat-family.yaml @@ -2,3 +2,9 @@ icinga2::globals::user: icinga icinga2::globals::group: icinga icinga2::globals::icinga2_bin: /sbin/icinga2 +icinga2::repo: + baseurl: 'http://packages.icinga.com/epel/%{facts.os.release.major}/release/' + descr: ICINGA (stable release for epel) + enabled: 1 + gpgcheck: 1 + gpgkey: http://packages.icinga.com/icinga.key diff --git a/data/Suse-family.yaml b/data/Suse-family.yaml index 47efca722..420e45b12 100644 --- a/data/Suse-family.yaml +++ b/data/Suse-family.yaml @@ -2,3 +2,8 @@ icinga2::globals::user: icinga icinga2::globals::group: icinga icinga2::globals::icinga2_bin: /usr/sbin/icinga2 +icinga2::repo: + baseurl: 'http://packages.icinga.com/SUSE/%{facts.os.release.full}/release/' + enabled: 1 + gpgcheck: 1 + gpgkey: http://packages.icinga.com/icinga.key diff --git a/data/Ubuntu.yaml b/data/Ubuntu.yaml new file mode 100644 index 000000000..fdb8faf81 --- /dev/null +++ b/data/Ubuntu.yaml @@ -0,0 +1,3 @@ +--- +icinga2::repo: + location: http://packages.icinga.com/ubuntu diff --git a/hiera.yaml b/hiera.yaml index 020268f01..97cfea537 100644 --- a/hiera.yaml +++ b/hiera.yaml @@ -6,6 +6,9 @@ defaults: data_hash: 'yaml_data' hierarchy: + - name: 'Operating System' + path: '%{facts.os.name}.yaml' + - name: 'Operating System Family Major Version' path: '%{facts.os.family}-family-%{facts.os.release.major}.yaml' diff --git a/manifests/repo.pp b/manifests/repo.pp index b207a789f..b898edf2e 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -20,96 +20,50 @@ if $::icinga2::manage_repo and $::icinga2::manage_package { + $repo = lookup('icinga2::repo', Hash, 'deep', {}) + case $::osfamily { 'redhat': { - case $::operatingsystem { - 'centos', 'redhat', 'oraclelinux', 'cloudlinux', 'xenserver', 'slc': { - yumrepo { 'icinga-stable-release': - baseurl => "http://packages.icinga.com/epel/${::operatingsystemmajrelease}/release/", - descr => 'ICINGA (stable release for epel)', - enabled => 1, - gpgcheck => 1, - gpgkey => 'http://packages.icinga.com/icinga.key', - } - - Yumrepo['icinga-stable-release'] -> Package<|tag == 'icinga2'|> - } - default: { - fail('Your plattform is not supported to manage a repository.') - } + yumrepo { 'icinga-stable-release': + * => $repo, } + Yumrepo['icinga-stable-release'] -> Package<|tag == 'icinga2'|> } + 'debian': { # handle icinga stable repo before all package resources # contain class problem! Apt::Source['icinga-stable-release'] -> Package <| tag == 'icinga2' |> Class['Apt::Update'] -> Package<|tag == 'icinga2'|> - case $::operatingsystem { - 'debian': { - include ::apt, ::apt::backports - apt::source { 'icinga-stable-release': - location => 'http://packages.icinga.com/debian', - release => "icinga-${::lsbdistcodename}", - repos => 'main', - key => { - id => 'F51A91A5EE001AA5D77D53C4C6E319C334410682', - source => 'http://packages.icinga.com/icinga.key', - }, - require => Class['::apt::backports'], - } - } - 'ubuntu': { - include ::apt - apt::source { 'icinga-stable-release': - location => 'http://packages.icinga.com/ubuntu', - release => "icinga-${::lsbdistcodename}", - repos => 'main', - key => { - id => 'F51A91A5EE001AA5D77D53C4C6E319C334410682', - source => 'http://packages.icinga.com/icinga.key', - }; - } - } - default: { - fail('Your plattform is not supported to manage a repository.') - } + + include ::apt + + apt::source { 'icinga-stable-release': + * => $repo, } - contain ::apt::update } + 'suse': { - file { '/etc/pki/GPG-KEY-icinga': - ensure => file, - source => 'http://packages.icinga.com/icinga.key', - } + Zypprepo['icinga-stable-release'] -> Package <| tag == 'icinga2' |> exec { 'import icinga gpg key': path => '/bin:/usr/bin:/sbin:/usr/sbin', - command => 'rpm --import /etc/pki/GPG-KEY-icinga', - unless => "rpm -q gpg-pubkey-`echo $(gpg --throw-keyids < /etc/pki/GPG-KEY-icinga) | cut --characters=11-18 | tr [A-Z] [a-z]`", - require => File['/etc/pki/GPG-KEY-icinga'], + command => "rpm --import ${repo['gpgkey']}", + unless => 'rpm -q gpg-pubkey-34410682', logoutput => 'on_failure', + before => Zypprepo['icinga-stable-release'], } - case $::operatingsystem { - 'SLES': { - zypprepo { 'icinga-stable-release': - baseurl => "http://packages.icinga.com/SUSE/${::operatingsystemrelease}/release/", - enabled => 1, - gpgcheck => 1, - require => Exec['import icinga gpg key'], - } - - Zypprepo['icinga-stable-release'] -> Package <| tag == 'icinga2' |> - } - default: { - fail('Your plattform is not supported to manage a repository.') - } + zypprepo { 'icinga-stable-release': + * => $repo, } } + 'windows': { warning("The Icinga Project doesn't offer chocolaty packages at the moment.") } + default: { fail('Your plattform is not supported to manage a repository.') }