diff --git a/manifests/package.pp b/manifests/package.pp index 45accaa42..2af4a0f63 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -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}") + } + } } } } diff --git a/manifests/package/amazon.pp b/manifests/package/amazon.pp deleted file mode 100644 index d4fb82314..000000000 --- a/manifests/package/amazon.pp +++ /dev/null @@ -1,20 +0,0 @@ -# Class: nginx::package::amazon -# -# This module manages NGINX package installation on ec2 amazon linux based systems -# -# Parameters: -# -# There are no default parameters for this class. -# -# Actions: -# -# Requires: -# -# Sample Usage: -# -# This class file is not called directly -class nginx::package::amazon { - package { 'nginx': - ensure => present, - } -} diff --git a/manifests/package/redhat.pp b/manifests/package/redhat.pp index 85fda93b3..8ee8ed721 100644 --- a/manifests/package/redhat.pp +++ b/manifests/package/redhat.pp @@ -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 @@ -45,7 +63,6 @@ package { $redhat_packages: ensure => present, - require => Yumrepo['nginx-release'], } } diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb index 3d8c90310..8ef3df5b0 100644 --- a/spec/classes/nginx_spec.rb +++ b/spec/classes/nginx_spec.rb @@ -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', diff --git a/spec/classes/package_spec.rb b/spec/classes/package_spec.rb index b1fcbc7a4..5c53b52ba 100644 --- a/spec/classes/package_spec.rb +++ b/spec/classes/package_spec.rb @@ -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') } @@ -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') } @@ -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 @@ -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/) }