Merge pull request #331 from rainopik/master
Upstream members can be exported and collected
This commit is contained in:
commit
6107c768f1
5 changed files with 85 additions and 9 deletions
|
@ -4,6 +4,7 @@
|
|||
#
|
||||
# Parameters:
|
||||
# [*members*] - Array of member URIs for NGINX to connect to. Must follow valid NGINX syntax.
|
||||
# If omitted, individual members should be defined with nginx::resource::upstream::member
|
||||
# [*ensure*] - Enables or disables the specified location (present|absent)
|
||||
# [*upstream_cfg_prepend*] - It expects a hash with custom directives to put before anything else inside upstream
|
||||
# [*upstream_fail_timeout*] - Set the fail_timeout for the upstream. Default is 10 seconds - As that is what Nginx does normally.
|
||||
|
@ -38,31 +39,58 @@
|
|||
# upstream_cfg_prepend => $my_config,
|
||||
# }
|
||||
define nginx::resource::upstream (
|
||||
$members,
|
||||
$members = undef,
|
||||
$ensure = 'present',
|
||||
$upstream_cfg_prepend = undef,
|
||||
$upstream_fail_timeout = '10s',
|
||||
) {
|
||||
|
||||
validate_array($members)
|
||||
if $members != undef {
|
||||
validate_array($members)
|
||||
}
|
||||
validate_re($ensure, '^(present|absent)$',
|
||||
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
|
||||
if ($upstream_cfg_prepend != undef) {
|
||||
validate_hash($upstream_cfg_prepend)
|
||||
}
|
||||
|
||||
File {
|
||||
Concat {
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
}
|
||||
|
||||
file { "/etc/nginx/conf.d/${name}-upstream.conf":
|
||||
concat { "/etc/nginx/conf.d/${name}-upstream.conf":
|
||||
ensure => $ensure ? {
|
||||
'absent' => absent,
|
||||
default => 'file',
|
||||
'file' => present,
|
||||
default => present,
|
||||
},
|
||||
content => template('nginx/conf.d/upstream.erb'),
|
||||
notify => Class['nginx::service'],
|
||||
}
|
||||
|
||||
# Uses: $name, $upstream_cfg_prepend
|
||||
concat::fragment { "${name}_upstream_header":
|
||||
target => "/etc/nginx/conf.d/${name}-upstream.conf",
|
||||
order => 10,
|
||||
content => template('nginx/conf.d/upstream_header.erb'),
|
||||
}
|
||||
|
||||
if $members != undef {
|
||||
# Uses: $members, $upstream_fail_timeout
|
||||
concat::fragment { "${name}_upstream_members":
|
||||
target => "/etc/nginx/conf.d/${name}-upstream.conf",
|
||||
order => 50,
|
||||
content => template('nginx/conf.d/upstream_members.erb'),
|
||||
}
|
||||
} else {
|
||||
# Collect exported members:
|
||||
Nginx::Resource::Upstream::Member <<| upstream == $name |>>
|
||||
}
|
||||
|
||||
concat::fragment { "${name}_upstream_footer":
|
||||
target => "/etc/nginx/conf.d/${name}-upstream.conf",
|
||||
order => 90,
|
||||
content => "}\n",
|
||||
}
|
||||
}
|
||||
|
|
48
manifests/resource/upstream/member.pp
Normal file
48
manifests/resource/upstream/member.pp
Normal file
|
@ -0,0 +1,48 @@
|
|||
# Define: nginx::resources::upstream::member
|
||||
#
|
||||
# Creates an upstream member inside the upstream block. Export this resource
|
||||
# in all upstream member servers and collect them on the NGINX server.
|
||||
#
|
||||
#
|
||||
# Requirements:
|
||||
# Requires storeconfigs on the Puppet Master to export and collect resources
|
||||
#
|
||||
#
|
||||
# Parameters:
|
||||
# [*upstream*] - The name of the upstream resource
|
||||
# [*server*] - Hostname or IP of the upstream member server
|
||||
# [*port*] - Port of the listening service on the upstream member
|
||||
# [*upstream_fail_timeout*] - Set the fail_timeout for the upstream. Default is 10 seconds
|
||||
#
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# Exporting the resource on a upstream member server:
|
||||
#
|
||||
# @@nginx::resource::upstream::member { $::fqdn:
|
||||
# upstream => 'proxypass',
|
||||
# server => $::ipaddress,
|
||||
# port => '3000',
|
||||
# }
|
||||
#
|
||||
#
|
||||
# Collecting the resource on the NGINX server:
|
||||
#
|
||||
# nginx::resource::upstream { 'proxypass':
|
||||
# ensure => present,
|
||||
# }
|
||||
#
|
||||
define nginx::resource::upstream::member (
|
||||
$upstream,
|
||||
$server,
|
||||
$port = '80',
|
||||
$upstream_fail_timeout = '10s',
|
||||
) {
|
||||
|
||||
# Uses: $server, $port, $upstream_fail_timeout
|
||||
concat::fragment { "${upstream}_upstream_member_${name}":
|
||||
target => "/etc/nginx/conf.d/${upstream}-upstream.conf",
|
||||
order => 40,
|
||||
content => template('nginx/conf.d/upstream_member.erb'),
|
||||
}
|
||||
}
|
|
@ -10,6 +10,3 @@ upstream <%= @name %> {
|
|||
<% end -%>
|
||||
<% end -%>
|
||||
<% end -%><% end -%>
|
||||
<% @members.each do |i| %>
|
||||
server <%= i %> fail_timeout=<%= @upstream_fail_timeout %>;<% end %>
|
||||
}
|
1
templates/conf.d/upstream_member.erb
Normal file
1
templates/conf.d/upstream_member.erb
Normal file
|
@ -0,0 +1 @@
|
|||
server <%= @server %>:<%= @port %> fail_timeout=<%= @upstream_fail_timeout %>;
|
2
templates/conf.d/upstream_members.erb
Normal file
2
templates/conf.d/upstream_members.erb
Normal file
|
@ -0,0 +1,2 @@
|
|||
<% @members.each do |i| %>
|
||||
server <%= i %> fail_timeout=<%= @upstream_fail_timeout %>;<% end %>
|
Loading…
Reference in a new issue