Skip to content

Commit

Permalink
update nginx::package to select the package class by $::osfamily
Browse files Browse the repository at this point in the history
There were some bugs in the existing $::operatingsystem based approach.

* amazon was it's own package set when it's properly part of $::osfamily ==
'redhat' as of facter >= 1.7.2

* gentoo was improperly part of the amazon package set; this patch removes
support for gentoo but it was broken anyways

modifications to nginx::package::redhat were made as well

* it no longer tries to setup the nginx.org yumrepo for fedora as no packages
for fedora are currently provided

* amazon release numbers are inconsistent with EL.  Unknown
$::lsbmajdistrelease values are now mapped to 6 so it's no longer nessicary to
test for $::lsbmajdistrelease being undefined.  This logic will need to be
reworked after RHEL7.x is released.

* the url to the nginx repo was including $::operatingsystem in it but
nginx.org only has package dirs for 'rhel' & 'centos' which are presently
identical; the usage of the 'rhel' dir has been hardcoded.  This fixes broken
yum repo setup for all $::osfamily == 'redhat' platforms other than redhat and
centos.
  • Loading branch information
Joshua Hoblitt committed Aug 22, 2013
1 parent 67f7405 commit e19a7fe
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 60 deletions.
30 changes: 19 additions & 11 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,41 @@
anchor { 'nginx::package::begin': }
anchor { 'nginx::package::end': }

case $::operatingsystem {
centos,fedora,rhel,redhat,scientific: {
case $::osfamily {
'redhat': {
class { 'nginx::package::redhat':
require => Anchor['nginx::package::begin'],
before => Anchor['nginx::package::end'],
}
}
amazon,gentoo: {
class { 'nginx::package::amazon':
require => Anchor['nginx::package::begin'],
before => Anchor['nginx::package::end'],
}
}
debian,ubuntu: {
'debian': {
class { 'nginx::package::debian':
require => Anchor['nginx::package::begin'],
before => Anchor['nginx::package::end'],
}
}
opensuse,suse: {
'suse': {
class { 'nginx::package::suse':
require => Anchor['nginx::package::begin'],
before => Anchor['nginx::package::end'],
}
}
default: {
fail("Module ${module_name} is not supported on ${::operatingsystem}")
case $::operatingsystem {
'amazon': {
# Amazon was added to osfamily RedHat in 1.7.2
# https://github.com/puppetlabs/facter/commit/c12d3b6c557df695a7b2b009da099f6a93c7bd31#lib/facter/osfamily.rb
warning("Module ${module_name} support for ${::operatingsystem} with facter < 1.7.2 is deprecated")
warning("Please upgrade from facter ${::facterversion} to >= 1.7.2")
class { 'nginx::package::redhat':
require => Anchor['nginx::package::begin'],
before => Anchor['nginx::package::end'],
}
}
default: {
fail("Module ${module_name} is not supported on ${::operatingsystem}")
}
}
}
}
}
20 changes: 0 additions & 20 deletions manifests/package/amazon.pp

This file was deleted.

53 changes: 35 additions & 18 deletions manifests/package/redhat.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,43 @@
class nginx::package::redhat {
$redhat_packages = ['nginx', 'gd', 'libXpm', 'libxslt']

if downcase($::operatingsystem) == 'redhat' {
$os_type = 'rhel'
} else {
$os_type = downcase($::operatingsystem)
}
case $::operatingsystem {
'fedora': {
# nginx.org does not supply RPMs for fedora
# fedora 18 provides 1.2.x packages
# fedora 19 has 1.4.x packages are in

if $::lsbmajdistrelease == undef {
$os_rel = regsubst($::operatingsystemrelease, '\..*$', '')
} else {
$os_rel = $::lsbmajdistrelease
}
# fedora 18 users will need to supply their own nginx 1.4 rpms and/or repo
if $::lsbmajdistrelease < 19 {
notice("${::operatingsystem} ${::lsbmajdistrelease} does not supply nginx >= 1.4 packages")
}
}
default: {
case $::lsbmajdistrelease {
5, 6: {
$os_rel = $::lsbmajdistrelease
}
default: {
# Amazon uses the year as the $::lsbmajdistrelease
$os_rel = 6
}
}

yumrepo { 'nginx-release':
baseurl => "http://nginx.org/packages/${os_type}/${os_rel}/\$basearch/",
descr => 'nginx repo',
enabled => '1',
gpgcheck => '1',
priority => '1',
gpgkey => "http://nginx.org/keys/nginx_signing.key",
# as of 2013-07-28
# http://nginx.org/packages/centos appears to be identical to
# http://nginx.org/packages/rhel
# no other dedicated dirs exist for platforms under $::osfamily == redhat
yumrepo { 'nginx-release':
baseurl => "http://nginx.org/packages/rhel/${os_rel}/\$basearch/",
descr => 'nginx repo',
enabled => '1',
gpgcheck => '1',
priority => '1',
gpgkey => 'http://nginx.org/keys/nginx_signing.key',
}

Yumrepo['nginx-release'] -> Package[$redhat_packages]
}
}

#Define file for nginx-repo so puppet doesn't delete it
Expand All @@ -45,7 +63,6 @@

package { $redhat_packages:
ensure => present,
require => Yumrepo['nginx-release'],
}

}
2 changes: 1 addition & 1 deletion spec/classes/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe 'nginx' do

shared_examples 'linux' do |operatingsystem, user|
let(:facts) {{ :kernel => 'linux', :operatingsystem => operatingsystem }}
let(:facts) {{ :kernel => 'linux', :operatingsystem => operatingsystem, :osfamily => operatingsystem }}

it { should contain_service('nginx').with(
:ensure => 'running',
Expand Down
31 changes: 21 additions & 10 deletions spec/classes/package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe 'nginx::package' do

shared_examples 'redhat' do |operatingsystem|
let(:facts) {{ :operatingsystem => operatingsystem }}
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat' }}
it { should contain_package('nginx') }
it { should contain_package('gd') }
it { should contain_package('libXpm') }
Expand All @@ -12,12 +12,12 @@
end

shared_examples 'debian' do |operatingsystem|
let(:facts) {{ :operatingsystem => operatingsystem }}
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'Debian'}}
it { should contain_file('/etc/apt/sources.list.d/nginx.list') }
end

shared_examples 'suse' do |operatingsystem|
let(:facts) {{ :operatingsystem => operatingsystem }}
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'Suse'}}
it { should contain_package('nginx-0.8') }
it { should contain_package('apache2') }
it { should contain_package('apache2-itk') }
Expand All @@ -26,17 +26,12 @@
end


context 'RedHat' do
context 'redhat' do
it_behaves_like 'redhat', 'centos'
it_behaves_like 'redhat', 'fedora'
it_behaves_like 'redhat', 'rhel'
it_behaves_like 'redhat', 'redhat'
it_behaves_like 'redhat', 'scientific'
end

context 'amazon' do
let(:facts) {{ :operatingsystem => 'amazon' }}
it { should contain_package('nginx') }
it_behaves_like 'redhat', 'amazon'
end

context 'debian' do
Expand All @@ -49,6 +44,22 @@
it_behaves_like 'suse', 'suse'
end

context 'amazon with facter < 1.7.2' do
let(:facts) {{ :operatingsystem => 'Amazon', :osfamily => 'Linux' }}
it { should contain_class('nginx::package::redhat') }
end

context 'fedora' do
# fedora is identical to the rest of osfamily RedHat except for not
# including nginx-release
let(:facts) {{ :operatingsystem => 'Fedora', :osfamily => 'RedHat' }}
it { should contain_package('nginx') }
it { should contain_package('gd') }
it { should contain_package('libXpm') }
it { should contain_package('libxslt') }
it { should_not contain_yumrepo('nginx-release') }
end

context 'other' do
let(:facts) {{ :operatingsystem => 'xxx' }}
it { expect { subject }.to raise_error(Puppet::Error, /Module nginx is not supported on xxx/) }
Expand Down

0 comments on commit e19a7fe

Please sign in to comment.