Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use some more puppet 4 features to reduce code #1058

Merged
merged 4 commits into from
Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
261 changes: 122 additions & 139 deletions manifests/init.pp

Large diffs are not rendered by default.

39 changes: 10 additions & 29 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,23 @@
# Sample Usage:
#
# This class file is not called directly
class nginx::package(
$package_name = $::nginx::params::package_name,
$package_source = 'nginx',
$package_ensure = 'present',
$package_flavor = undef,
$passenger_package_ensure = 'present',
$manage_repo = $::nginx::params::manage_repo,
) {
class nginx::package {

assert_private()
$package_name = $::nginx::package_name
$package_source = $::nginx::package_source
$package_ensure = $::nginx::package_ensure
$package_flavor = $::nginx::package_flavor
$passenger_package_ensure = $::nginx::passenger_package_ensure
$manage_repo = $::nginx::manage_repo

anchor { 'nginx::package::begin': }
anchor { 'nginx::package::end': }
assert_private()

case $::osfamily {
'redhat': {
class { '::nginx::package::redhat':
manage_repo => $manage_repo,
package_source => $package_source,
package_ensure => $package_ensure,
passenger_package_ensure => $passenger_package_ensure,
package_name => $package_name,
require => Anchor['nginx::package::begin'],
before => Anchor['nginx::package::end'],
}
contain ::nginx::package::redhat
}
'debian': {
class { '::nginx::package::debian':
package_name => $package_name,
package_source => $package_source,
package_ensure => $package_ensure,
passenger_package_ensure => $passenger_package_ensure,
manage_repo => $manage_repo,
require => Anchor['nginx::package::begin'],
before => Anchor['nginx::package::end'],
}
contain ::nginx::package::debian
}
'Solaris': {
# $package_name needs to be specified. SFEnginx,CSWnginx depending on
Expand Down
15 changes: 8 additions & 7 deletions manifests/package/debian.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
# Sample Usage:
#
# This class file is not called directly
class nginx::package::debian (
$manage_repo = true,
$package_name = 'nginx',
$package_source = 'nginx',
$package_ensure = 'present',
$passenger_package_ensure = 'present'
) {
class nginx::package::debian {

$package_name = $::nginx::package_name
$package_source = $::nginx::package_source
$package_ensure = $::nginx::package_ensure
$package_flavor = $::nginx::package_flavor
$passenger_package_ensure = $::nginx::passenger_package_ensure
$manage_repo = $::nginx::manage_repo

$distro = downcase($::operatingsystem)

Expand Down
22 changes: 11 additions & 11 deletions manifests/package/redhat.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
# Sample Usage:
#
# This class file is not called directly
class nginx::package::redhat (
$manage_repo = true,
$package_ensure = 'present',
$package_name = 'nginx',
$package_source = 'nginx-stable',
$passenger_package_ensure = 'present',
) {
class nginx::package::redhat {

$package_name = $::nginx::package_name
$package_source = $::nginx::package_source
$package_ensure = $::nginx::package_ensure
$package_flavor = $::nginx::package_flavor
$passenger_package_ensure = $::nginx::passenger_package_ensure
$manage_repo = $::nginx::manage_repo

#Install the CentOS-specific packages on that OS, otherwise assume it's a RHEL
#clone and provide the Red Hat-specific package. This comes into play when not
#on RHEL or CentOS and $manage_repo is set manually to 'true'.
if $::operatingsystem == 'centos' {
$_os = 'centos'
} else {
$_os = 'rhel'
$_os = $::operatingsystem? {
'centos' => 'centos',
default => 'rhel'
}

if $manage_repo {
Expand Down
8 changes: 0 additions & 8 deletions spec/classes/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@
describe 'with defaults' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('nginx') }
it { is_expected.to contain_anchor('nginx::begin') }
it { is_expected.to contain_class('nginx::package').that_requires('Anchor[nginx::begin]') }
it { is_expected.to contain_class('nginx::config').that_requires('Class[nginx::package]') }
it { is_expected.to contain_class('nginx::service').that_subscribes_to('Anchor[nginx::begin]') }
it { is_expected.to contain_class('nginx::service').that_subscribes_to('Class[nginx::package]') }
it { is_expected.to contain_class('nginx::service').that_subscribes_to('Class[nginx::config]') }
it { is_expected.to contain_anchor('nginx::end').that_requires('Class[nginx::service]') }
it { is_expected.to contain_nginx__resource__upstream('upstream1') }
it { is_expected.to contain_nginx__resource__server('test2.local') }
it { is_expected.to contain_nginx__resource__server('test2.local').with_listen_options('default_server') }
Expand Down Expand Up @@ -60,8 +56,6 @@
end
it { is_expected.to contain_yumrepo('nginx-release').that_comes_before('Package[nginx]') }
it { is_expected.to contain_yumrepo('passenger').that_comes_before('Package[nginx]') }
it { is_expected.to contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::redhat]') }
it { is_expected.to contain_anchor('nginx::package::end').that_requires('Class[nginx::package::redhat]') }
end

context 'package_source => nginx-mainline' do
Expand Down Expand Up @@ -164,8 +158,6 @@
'key' => { 'id' => '573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62' }
)
end
it { is_expected.to contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::debian]') }
it { is_expected.to contain_anchor('nginx::package::end').that_requires('Class[nginx::package::debian]') }
end

context 'package_source => nginx-mainline' do
Expand Down
1 change: 1 addition & 0 deletions templates/mailhost/mailhost.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ server {
listen <%= @listen_ip %>:<%= @listen_port %><% if @listen_options %> <%= @listen_options %><% end %>;
<%- end -%>
<%# check to see if ipv6 support exists in the kernel before applying -%>
<%# FIXME this logic is duplicated all over the place -%>
<%- if @ipv6_enable && (defined? @ipaddress6) -%>
<%- if @ipv6_listen_ip.is_a?(Array) then -%>
<%- @ipv6_listen_ip.each do |ipv6| -%>
Expand Down
1 change: 1 addition & 0 deletions templates/mailhost/mailhost_ssl.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ server {
listen <%= @listen_ip %>:<%= @ssl_port %>;
<%- end -%>
<%# check to see if ipv6 support exists in the kernel before applying -%>
<%# FIXME this logic is duplicated all over the place -%>
<%- if @ipv6_enable && (defined? @ipaddress6) -%>
<%- if @ipv6_listen_ip.is_a?(Array) then -%>
<%- @ipv6_listen_ip.each do |ipv6| -%>
Expand Down
1 change: 1 addition & 0 deletions templates/server/server_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ server {
<%- end -%>
<%- end -%>
<%# check to see if ipv6 support exists in the kernel before applying -%>
<%# FIXME this logic is duplicated all over the place -%>
<%- if @ipv6_enable && (defined? @ipaddress6) -%>
<%- if @ipv6_listen_ip.is_a?(Array) then -%>
<%- @ipv6_listen_ip.each do |ipv6| -%>
Expand Down
1 change: 1 addition & 0 deletions templates/server/server_ssl_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ server {
listen <%= @listen_ip %>:<%= @ssl_port %> <% if @ssl_listen_option %>ssl<% end %><% if @http2 == 'on' %> http2<% end %><% if @spdy == 'on' %> spdy<% end %><% if @listen_options %> <%= @listen_options %><% end %>;
<%- end -%>
<%# check to see if ipv6 support exists in the kernel before applying -%>
<%# FIXME this logic is duplicated all over the place -%>
<%- if @ipv6_enable && (defined? @ipaddress6) -%>
<%- if @ipv6_listen_ip.is_a?(Array) then -%>
<%- @ipv6_listen_ip.each do |ipv6| -%>
Expand Down
1 change: 1 addition & 0 deletions templates/streamhost/streamhost.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ server {
listen <%= @listen_ip %>:<%= @listen_port %><% if @listen_options %> <%= @listen_options %><% end %>;
<%- end -%>
<%# check to see if ipv6 support exists in the kernel before applying -%>
<%# FIXME this logic is duplicated all over the place -%>
<%- if @ipv6_enable && (defined? @ipaddress6) -%>
<%- if @ipv6_listen_ip.is_a?(Array) then -%>
<%- @ipv6_listen_ip.each do |ipv6| -%>
Expand Down
1 change: 1 addition & 0 deletions types/errorlogseverity.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Nginx::ErrorLogSeverity = Enum['debug','info','notice','warn','error','crit','alert','emerg']