diff --git a/manifests/package.pp b/manifests/package.pp index 1980a7a..6c76032 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -27,6 +27,7 @@ class nginx::package( 'redhat': { class { '::nginx::package::redhat': manage_repo => $manage_repo, + package_source => $package_source, package_ensure => $package_ensure, package_name => $package_name, require => Anchor['nginx::package::begin'], diff --git a/manifests/package/debian.pp b/manifests/package/debian.pp index e695513..6f510dc 100644 --- a/manifests/package/debian.pp +++ b/manifests/package/debian.pp @@ -32,7 +32,7 @@ class nginx::package::debian( Exec['apt_update'] -> Package['nginx'] case $package_source { - 'nginx': { + 'nginx', 'nginx-stable': { apt::source { 'nginx': location => "http://nginx.org/packages/${distro}", repos => 'nginx', @@ -40,6 +40,14 @@ class nginx::package::debian( key_source => 'http://nginx.org/keys/nginx_signing.key', } } + 'nginx-mainline': { + apt::source { 'nginx': + location => "http://nginx.org/packages/mainline/${distro}", + repos => 'nginx', + key => '7BD9BF62', + key_source => 'http://nginx.org/keys/nginx_signing.key', + } + } 'passenger': { apt::source { 'nginx': location => 'https://oss-binaries.phusionpassenger.com/apt/passenger', @@ -54,7 +62,9 @@ class nginx::package::debian( require => Exec['apt_update'], } } - default: {} + default: { + fail("\$package_source must be 'nginx-stable', 'nginx-mainline' or 'passenger'. It was set to '${package_source}'") + } } } } diff --git a/manifests/package/redhat.pp b/manifests/package/redhat.pp index 5096092..5c95a36 100644 --- a/manifests/package/redhat.pp +++ b/manifests/package/redhat.pp @@ -17,6 +17,7 @@ class nginx::package::redhat ( $manage_repo = true, $package_ensure = 'present', $package_name = 'nginx', + $package_source = 'nginx-stable', ) { #Install the CentOS-specific packages on that OS, otherwise assume it's a RHEL @@ -28,7 +29,9 @@ class nginx::package::redhat ( $_os = 'rhel' } - if $manage_repo { + if $manage_repo { + case $package_source { + 'nginx', 'nginx-stable': { yumrepo { 'nginx-release': baseurl => "http://nginx.org/packages/${_os}/${::operatingsystemmajrelease}/\$basearch/", descr => 'nginx repo', @@ -39,6 +42,22 @@ class nginx::package::redhat ( before => Package[$package_name], } } + 'nginx-mainline': { + yumrepo { 'nginx-release': + baseurl => "http://nginx.org/packages/mainline/${_os}/${::operatingsystemmajrelease}/\$basearch/", + descr => 'nginx repo', + enabled => '1', + gpgcheck => '1', + priority => '1', + gpgkey => 'http://nginx.org/keys/nginx_signing.key', + before => Package[$package_name], + } + } + default: { + fail("\$package_source must be 'nginx-stable' or 'nginx-mainline'. It was set to '${package_source}'") + } + } + } package { 'nginx': ensure => $package_ensure, diff --git a/spec/classes/package_spec.rb b/spec/classes/package_spec.rb index e1d6167..77c8344 100644 --- a/spec/classes/package_spec.rb +++ b/spec/classes/package_spec.rb @@ -18,6 +18,13 @@ describe 'nginx::package' do it { is_expected.to contain_anchor('nginx::package::end').that_requires('Class[nginx::package::redhat]') } end + context "package_source => nginx-mainline" do + let(:params) {{ :package_source => 'nginx-mainline' }} + it { is_expected.to contain_yumrepo('nginx-release').with( + 'baseurl' => "http://nginx.org/packages/mainline/#{operatingsystem == 'CentOS' ? 'centos' : 'rhel'}/6/$basearch/", + )} + end + context "manage_repo => false" do let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat', :operatingsystemmajrelease => '7' }} let(:params) {{ :manage_repo => false }} @@ -67,6 +74,13 @@ describe 'nginx::package' do it { is_expected.to contain_anchor('nginx::package::end').that_requires('Class[nginx::package::debian]') } end + context "package_source => nginx-mainline" do + let(:params) {{ :package_source => 'nginx-mainline' }} + it { is_expected.to contain_apt__source('nginx').with( + 'location' => "http://nginx.org/packages/mainline/#{operatingsystem.downcase}", + )} + end + context "package_source => 'passenger'" do let(:params) {{ :package_source => 'passenger' }} it { is_expected.to contain_package('nginx') }