Add an ensure option to nginx::resource::upstream::member.

Currently there is no way to ensure => absent.  I'm using these with
stored configs to have servers register the member only, not the
upstream.  Removing them in a mis-configured incident is a bit of a
burden without ensure => absent.

Tests are passing under Ruby 2.1
This commit is contained in:
Kevin Wolf 2015-08-28 15:07:23 -05:00
parent 398d0c9ae7
commit 52a1f6e653

View file

@ -9,6 +9,7 @@
# #
# #
# Parameters: # Parameters:
# [*ensure*] - Enables or disables the specified member (present|absent)
# [*upstream*] - The name of the upstream resource # [*upstream*] - The name of the upstream resource
# [*server*] - Hostname or IP of the upstream member server # [*server*] - Hostname or IP of the upstream member server
# [*port*] - Port of the listening service on the upstream member # [*port*] - Port of the listening service on the upstream member
@ -20,6 +21,7 @@
# Exporting the resource on a upstream member server: # Exporting the resource on a upstream member server:
# #
# @@nginx::resource::upstream::member { $::fqdn: # @@nginx::resource::upstream::member { $::fqdn:
# ensure => present,
# upstream => 'proxypass', # upstream => 'proxypass',
# server => $::ipaddress, # server => $::ipaddress,
# port => '3000', # port => '3000',
@ -35,12 +37,22 @@
define nginx::resource::upstream::member ( define nginx::resource::upstream::member (
$upstream, $upstream,
$server, $server,
$ensure = 'present',
$port = '80', $port = '80',
$upstream_fail_timeout = '10s', $upstream_fail_timeout = '10s',
) { ) {
validate_re($ensure, '^(present|absent)$',
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
$ensure_real = $ensure ? {
'absent' => absent,
default => present,
}
# Uses: $server, $port, $upstream_fail_timeout # Uses: $server, $port, $upstream_fail_timeout
concat::fragment { "${upstream}_upstream_member_${name}": concat::fragment { "${upstream}_upstream_member_${name}":
ensure => $ensure_real,
target => "${::nginx::config::conf_dir}/conf.d/${upstream}-upstream.conf", target => "${::nginx::config::conf_dir}/conf.d/${upstream}-upstream.conf",
order => 40, order => 40,
content => template('nginx/conf.d/upstream_member.erb'), content => template('nginx/conf.d/upstream_member.erb'),