forked from glarizza/puppet-haproxy
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from hunner/mailers
(MODULES-3055) Add mailers
- Loading branch information
Showing
12 changed files
with
209 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# == Define Resource Type: haproxy::mailer | ||
# | ||
# This type will set up a mailer entry inside the mailers configuration block in | ||
# haproxy.cfg on the load balancer. Currently, it has the ability to | ||
# specify the instance name, ip address, ports and server_names. | ||
# | ||
# Automatic discovery of mailer nodes may be implemented by exporting the mailer | ||
# resource for all HAProxy balancer servers that are configured in the same HA | ||
# block and then collecting them on all load balancers. | ||
# | ||
# === Parameters: | ||
# | ||
# [*mailers_name*] | ||
# Specifies the mailer in which this load balancer needs to be added. | ||
# | ||
# [*server_names*] | ||
# Sets the name of the mailer server in the mailers configuration block. | ||
# Defaults to the hostname. Can be an array. If this parameter is | ||
# specified as an array, it must be the same length as the | ||
# ipaddresses parameter's array. A mailer is created for each pair | ||
# of server\_names and ipaddresses in the array. | ||
# | ||
# [*ipaddresses*] | ||
# Specifies the IP address used to contact the mailer member server. | ||
# Can be an array. If this parameter is specified as an array it | ||
# must be the same length as the server\_names parameter's array. | ||
# A mailer is created for each pair of address and server_name. | ||
# | ||
# [*ports*] | ||
# Sets the port on which the mailer is going to share the state. | ||
|
||
define haproxy::mailer ( | ||
$mailers_name, | ||
$port, | ||
$server_names = $::hostname, | ||
$ipaddresses = $::ipaddress, | ||
$instance = 'haproxy', | ||
) { | ||
include ::haproxy::params | ||
if $instance == 'haproxy' { | ||
$instance_name = 'haproxy' | ||
$config_file = $::haproxy::config_file | ||
} else { | ||
$instance_name = "haproxy-${instance}" | ||
$config_file = inline_template($haproxy::params::config_file_tmpl) | ||
} | ||
|
||
# Templates uses $ipaddresses, $server_name, $ports, $option | ||
concat::fragment { "${instance_name}-mailers-${mailers_name}-${name}": | ||
order => "40-mailers-01-${mailers_name}-${name}", | ||
target => $config_file, | ||
content => template('haproxy/haproxy_mailer.erb'), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Private define | ||
define haproxy::mailer::collect_exported { | ||
if $caller_module_name != $module_name { | ||
fail("Use of private class ${name} by ${caller_module_name}") | ||
} | ||
|
||
Haproxy::Mailer <<| mailers_name == $name |>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# == Defined Type: haproxy::mailers | ||
# | ||
# This type will set up a mailers entry in haproxy.cfg on the load balancer. | ||
# This setting makes it possible to send emails during state changes. | ||
# | ||
# === Parameters | ||
# | ||
# [*name*] | ||
# Sets the mailers' name. Generally it will be the namevar of the | ||
# defined resource type. This value appears right after the | ||
# 'mailers' statement in haproxy.cfg | ||
|
||
define haproxy::mailers ( | ||
$collect_exported = true, | ||
$instance = 'haproxy', | ||
) { | ||
|
||
# We derive these settings so that the caller only has to specify $instance. | ||
include ::haproxy::params | ||
if $instance == 'haproxy' { | ||
$instance_name = 'haproxy' | ||
$config_file = $::haproxy::config_file | ||
} else { | ||
$instance_name = "haproxy-${instance}" | ||
$config_file = inline_template($haproxy::params::config_file_tmpl) | ||
} | ||
|
||
# Template uses: $name | ||
concat::fragment { "${instance_name}-${name}_mailers_block": | ||
order => "40-mailers-00-${name}", | ||
target => $config_file, | ||
content => template('haproxy/haproxy_mailers_block.erb'), | ||
} | ||
|
||
if $collect_exported { | ||
haproxy::mailer::collect_exported { $name: } | ||
} | ||
# else: the resources have been created and they introduced their | ||
# concat fragments. We don't have to do anything about them. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'spec_helper' | ||
|
||
describe 'haproxy::mailer' do | ||
let :pre_condition do | ||
'class{"haproxy": | ||
config_file => "/tmp/haproxy.cfg" | ||
} | ||
' | ||
end | ||
let(:title) { 'dero' } | ||
let(:facts) do | ||
{ | ||
:ipaddress => '1.1.1.1', | ||
:hostname => 'dero', | ||
:concat_basedir => '/foo', | ||
:osfamily => 'RedHat', | ||
} | ||
end | ||
|
||
context 'with a single mailer' do | ||
let(:params) do | ||
{ | ||
:mailers_name => 'tyler', | ||
:port => 1024, | ||
} | ||
end | ||
|
||
it { should contain_concat__fragment('haproxy-mailers-tyler-dero').with( | ||
'order' => '40-mailers-01-tyler-dero', | ||
'target' => '/tmp/haproxy.cfg', | ||
'content' => " mailer dero 1.1.1.1:1024\n" | ||
) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'spec_helper' | ||
|
||
describe 'haproxy::mailers' do | ||
let :pre_condition do | ||
'class{"haproxy": | ||
config_file => "/tmp/haproxy.cfg" | ||
} | ||
' | ||
end | ||
let(:facts) {{ | ||
:ipaddress => '1.1.1.1', | ||
:concat_basedir => '/foo', | ||
:osfamily => 'RedHat', | ||
}} | ||
|
||
context "when no options are passed" do | ||
let(:title) { 'bar' } | ||
|
||
it { should contain_concat__fragment('haproxy-bar_mailers_block').with( | ||
'order' => '40-mailers-00-bar', | ||
'target' => '/tmp/haproxy.cfg', | ||
'content' => "\nmailers bar\n" | ||
) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<% Array(@ipaddresses).zip(Array(@server_names)).each do |ipaddress,host| -%> | ||
mailer <%= host %> <%= ipaddress %>:<%= @port %> | ||
<% end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
mailers <%= @name %> |