From 3ab65f56a61cfedbe75a3b41143f0d44fbad0a93 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Fri, 12 Oct 2012 11:28:24 -0700 Subject: Rename everything! What is renamed: - Class/define: - haproxy::config to haproxy::listen - haproxy::data to haproxy::params - Parameters: - haproxy::listen listen_ip to ipaddress - haproxy::listen config_options to options - haproxy haproxy_global_options to global_options - haproxy haproxy_defaults_options to defaults_options --- manifests/balancermember.pp | 4 +- manifests/config.pp | 100 ------------------------------------ manifests/data.pp | 65 ------------------------ manifests/init.pp | 32 +++++------- manifests/listen.pp | 101 +++++++++++++++++++++++++++++++++++++ manifests/params.pp | 65 ++++++++++++++++++++++++ spec/defines/config_spec.rb | 36 ------------- spec/defines/listen_spec.rb | 36 +++++++++++++ templates/haproxy-base.cfg.erb | 6 +-- templates/haproxy_config_block.erb | 11 ---- templates/haproxy_listen_block.erb | 11 ++++ tests/init.pp | 83 +++++++++++++++++------------- 12 files changed, 280 insertions(+), 270 deletions(-) delete mode 100644 manifests/config.pp delete mode 100644 manifests/data.pp create mode 100644 manifests/listen.pp create mode 100644 manifests/params.pp delete mode 100644 spec/defines/config_spec.rb create mode 100644 spec/defines/listen_spec.rb delete mode 100644 templates/haproxy_config_block.erb create mode 100644 templates/haproxy_listen_block.erb diff --git a/manifests/balancermember.pp b/manifests/balancermember.pp index af5728e..d43d98a 100644 --- a/manifests/balancermember.pp +++ b/manifests/balancermember.pp @@ -22,8 +22,8 @@ # # [*listening_service*] # The haproxy service's instance name (or, the title of the -# haproxy::config resource). This must match up with a declared -# haproxy::config resource. +# haproxy::listen resource). This must match up with a declared +# haproxy::listen resource. # # [*balancer_port*] # A unique port for which the balancer member will accept connections diff --git a/manifests/config.pp b/manifests/config.pp deleted file mode 100644 index b9caf15..0000000 --- a/manifests/config.pp +++ /dev/null @@ -1,100 +0,0 @@ -# == Define Resource Type: haproxy::config -# -# This type will setup a listening service configuration block inside -# the haproxy.cfg file on an haproxy load balancer. Each listening service -# configuration needs one or more load balancer member server (that can be -# declared with the haproxy::balancermember defined resource type). Using -# storeconfigs, you can export the haproxy::balancermember resources on all -# load balancer member servers, and then collect them on a single haproxy -# load balancer server. -# -# === Requirement/Dependencies: -# -# Currently requires the ripienaar/concat module on the Puppet Forge and -# uses storeconfigs on the Puppet Master to export/collect resources -# from all balancer members. -# -# === Parameters -# -# [*name*] -# The namevar of the defined resource type is the listening service's name. -# This name goes right after the 'listen' statement in haproxy.cfg -# -# [*ports*] -# Ports on which the proxy will listen for connections on the ip address -# specified in the virtual_ip parameter. Accepts either a single string or -# an array of strings which may be a unique port or a hyphenated port range. -# -# [*order*] -# The order, or numerical weight, of the fragment created by this defined -# resource type. This is necessary to ensure the fragment is associated -# with the correct listening service instance. -# -# [*listen_ip*] -# The ip address the proxy binds to. Empty addresses, '*', and '0.0.0.0' -# mean that the proxy listens to all valid addresses on the system. -# -# [*mode*] -# The mode of operation for the listening service. Valid values are 'tcp', -# HTTP', and 'health'. -# -# [*config_options*] -# A hash of options that are inserted into the listening service -# configuration block. -# -# [*collect_exported*] -# Boolean, default 'true'. True means 'collect exported @@balancermember resources' -# (for the case when every balancermember node exports itself), false means -# 'rely on the existing declared balancermember resources' (for the case when you -# know the full set of balancermembers in advance and use haproxy::balancermember -# with array arguments, which allows you to deploy everything in 1 run) -# -# -# === Examples -# -# Exporting the resource for a balancer member: -# -# haproxy::config { 'puppet00': -# order => '20', -# listen_ip => $::ipaddress, -# ports => '18140', -# mode => 'tcp', -# config_options => { -# 'option' => [ -# 'tcplog', -# 'ssl-hello-chk' -# ], -# 'balance' => 'roundrobin' -# }, -# } -# -# === Authors -# -# Gary Larizza -# -define haproxy::config ( - $ports, - $order = '20', - $listen_ip = $::ipaddress, - $mode = 'tcp', - $collect_exported = true, - $config_options = { - 'option' => [ - 'tcplog', - 'ssl-hello-chk' - ], - 'balance' => 'roundrobin' - } -) { - concat::fragment { "${name}_config_block": - order => $order, - target => '/etc/haproxy/haproxy.cfg', - content => template('haproxy/haproxy_config_block.erb'), - } - - if $collect_exported { - Haproxy::Balancermember <<| listening_service == $name |>> - } - # else: the resources have been created and they introduced their - # concat fragments. We don't have to do anything about them. -} diff --git a/manifests/data.pp b/manifests/data.pp deleted file mode 100644 index ab920ed..0000000 --- a/manifests/data.pp +++ /dev/null @@ -1,65 +0,0 @@ -# == Class: haproxy::data -# -# This is a container class holding default parameters for for haproxy class. -# currently, only the Redhat family is supported, but this can be easily -# extended by changing package names and configuration file paths. -# -class haproxy::data { - case $osfamily { - Redhat: { - $haproxy_global_options = { - 'log' => "${::ipaddress} local0", - 'chroot' => '/var/lib/haproxy', - 'pidfile' => '/var/run/haproxy.pid', - 'maxconn' => '4000', - 'user' => 'haproxy', - 'group' => 'haproxy', - 'daemon' => '', - 'stats' => 'socket /var/lib/haproxy/stats' - } - $haproxy_defaults_options = { - 'log' => 'global', - 'stats' => 'enable', - 'option' => 'redispatch', - 'retries' => '3', - 'timeout' => [ - 'http-request 10s', - 'queue 1m', - 'connect 10s', - 'client 1m', - 'server 1m', - 'check 10s', - ], - 'maxconn' => '8000' - } - } - Debian: { - $haproxy_global_options = { - 'log' => "${::ipaddress} local0", - 'chroot' => '/var/lib/haproxy', - 'pidfile' => '/var/run/haproxy.pid', - 'maxconn' => '4000', - 'user' => 'haproxy', - 'group' => 'haproxy', - 'daemon' => '', - 'stats' => 'socket /var/lib/haproxy/stats' - } - $haproxy_defaults_options = { - 'log' => 'global', - 'stats' => 'enable', - 'option' => 'redispatch', - 'retries' => '3', - 'timeout' => [ - 'http-request 10s', - 'queue 1m', - 'connect 10s', - 'client 1m', - 'server 1m', - 'check 10s', - ], - 'maxconn' => '8000' - } - } - default: { fail("The $::osfamily operating system is not supported with the haproxy module") } - } -} diff --git a/manifests/init.pp b/manifests/init.pp index 7bf6aa9..92df8b8 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,4 +1,4 @@ -# == Class: puppet-haproxy +# == Class: haproxy # # A Puppet module, using storeconfigs, to model an haproxy configuration. # Currently VERY limited - assumes Redhat/CentOS setup. Pull requests accepted! @@ -15,13 +15,13 @@ # Chooses whether haproxy should be installed or ensured absent. # Currently ONLY accepts valid boolean true/false values. # -# [*haproxy_global_options*] +# [*global_options*] # A hash of all the haproxy global options. If you want to specify more # than one option (i.e. multiple timeout or stats options), pass those # options as an array and you will get a line for each of them in the # resultant haproxy.cfg file. # -# [*haproxy_defaults_options*] +# [*defaults_options*] # A hash of all the haproxy defaults options. If you want to specify more # than one option (i.e. multiple timeout or stats options), pass those # options as an array and you will get a line for each of them in the @@ -31,8 +31,8 @@ # === Examples # # class { 'haproxy': -# enable => true, -# haproxy_global_options => { +# enable => true, +# global_options => { # 'log' => "${::ipaddress} local0", # 'chroot' => '/var/lib/haproxy', # 'pidfile' => '/var/run/haproxy.pid', @@ -42,7 +42,7 @@ # 'daemon' => '', # 'stats' => 'socket /var/lib/haproxy/stats' # }, -# haproxy_defaults_options => { +# defaults_options => { # 'log' => 'global', # 'stats' => 'enable', # 'option' => 'redispatch', @@ -59,16 +59,12 @@ # }, # } # -# === Authors -# -# Gary Larizza -# class haproxy ( - $manage_service = true, - $enable = true, - $haproxy_global_options = $haproxy::data::haproxy_global_options, - $haproxy_defaults_options = $haproxy::data::haproxy_defaults_options -) inherits haproxy::data { + $manage_service = true, + $enable = true, + $global_options = $haproxy::params::global_options, + $defaults_options = $haproxy::params::defaults_options +) inherits haproxy::params { include concat::setup package { 'haproxy': @@ -95,7 +91,7 @@ class haproxy ( content => "# This file managed by Puppet\n", } - # Most of the variables are used inside the haproxy-base.cfg.erb template + # Template uses $global_options, $defaults_options concat::fragment { 'haproxy-base': target => '/etc/haproxy/haproxy.cfg', order => '10', @@ -110,7 +106,7 @@ class haproxy ( } } - file { $haproxy_global_options['chroot']: + file { $global_options['chroot']: ensure => directory, before => Service['haproxy'], } @@ -132,7 +128,7 @@ class haproxy ( hasstatus => true, require => [ Concat['/etc/haproxy/haproxy.cfg'], - File[$haproxy_global_options['chroot']], + File[$global_options['chroot']], ], } } diff --git a/manifests/listen.pp b/manifests/listen.pp new file mode 100644 index 0000000..d4ddd60 --- /dev/null +++ b/manifests/listen.pp @@ -0,0 +1,101 @@ +# == Define Resource Type: haproxy::listen +# +# This type will setup a listening service configuration block inside +# the haproxy.cfg file on an haproxy load balancer. Each listening service +# configuration needs one or more load balancer member server (that can be +# declared with the haproxy::balancermember defined resource type). Using +# storeconfigs, you can export the haproxy::balancermember resources on all +# load balancer member servers, and then collect them on a single haproxy +# load balancer server. +# +# === Requirement/Dependencies: +# +# Currently requires the ripienaar/concat module on the Puppet Forge and +# uses storeconfigs on the Puppet Master to export/collect resources +# from all balancer members. +# +# === Parameters +# +# [*name*] +# The namevar of the defined resource type is the listening service's name. +# This name goes right after the 'listen' statement in haproxy.cfg +# +# [*ports*] +# Ports on which the proxy will listen for connections on the ip address +# specified in the virtual_ip parameter. Accepts either a single string or +# an array of strings which may be a unique port or a hyphenated port range. +# +# [*order*] +# The order, or numerical weight, of the fragment created by this defined +# resource type. This is necessary to ensure the fragment is associated +# with the correct listening service instance. +# +# [*ipaddress*] +# The ip address the proxy binds to. Empty addresses, '*', and '0.0.0.0' +# mean that the proxy listens to all valid addresses on the system. +# +# [*mode*] +# The mode of operation for the listening service. Valid values are 'tcp', +# HTTP', and 'health'. +# +# [*options*] +# A hash of options that are inserted into the listening service +# configuration block. +# +# [*collect_exported*] +# Boolean, default 'true'. True means 'collect exported @@balancermember resources' +# (for the case when every balancermember node exports itself), false means +# 'rely on the existing declared balancermember resources' (for the case when you +# know the full set of balancermembers in advance and use haproxy::balancermember +# with array arguments, which allows you to deploy everything in 1 run) +# +# +# === Examples +# +# Exporting the resource for a balancer member: +# +# haproxy::listen { 'puppet00': +# order => '20', +# ipaddress => $::ipaddress, +# ports => '18140', +# mode => 'tcp', +# options => { +# 'option' => [ +# 'tcplog', +# 'ssl-hello-chk' +# ], +# 'balance' => 'roundrobin' +# }, +# } +# +# === Authors +# +# Gary Larizza +# +define haproxy::listen ( + $ports, + $order = '20', + $ipaddress = $::ipaddress, + $mode = 'tcp', + $collect_exported = true, + $options = { + 'option' => [ + 'tcplog', + 'ssl-hello-chk' + ], + 'balance' => 'roundrobin' + } +) { + # Template uses: $name, $ipaddress, $ports, $options + concat::fragment { "${name}_listen_block": + order => $order, + target => '/etc/haproxy/haproxy.cfg', + content => template('haproxy/haproxy_listen_block.erb'), + } + + if $collect_exported { + Haproxy::Balancermember <<| listening_service == $name |>> + } + # else: the resources have been created and they introduced their + # concat fragments. We don't have to do anything about them. +} diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 0000000..53442dd --- /dev/null +++ b/manifests/params.pp @@ -0,0 +1,65 @@ +# == Class: haproxy::params +# +# This is a container class holding default parameters for for haproxy class. +# currently, only the Redhat family is supported, but this can be easily +# extended by changing package names and configuration file paths. +# +class haproxy::params { + case $osfamily { + Redhat: { + $global_options = { + 'log' => "${::ipaddress} local0", + 'chroot' => '/var/lib/haproxy', + 'pidfile' => '/var/run/haproxy.pid', + 'maxconn' => '4000', + 'user' => 'haproxy', + 'group' => 'haproxy', + 'daemon' => '', + 'stats' => 'socket /var/lib/haproxy/stats' + } + $defaults_options = { + 'log' => 'global', + 'stats' => 'enable', + 'option' => 'redispatch', + 'retries' => '3', + 'timeout' => [ + 'http-request 10s', + 'queue 1m', + 'connect 10s', + 'client 1m', + 'server 1m', + 'check 10s', + ], + 'maxconn' => '8000' + } + } + Debian: { + $global_options = { + 'log' => "${::ipaddress} local0", + 'chroot' => '/var/lib/haproxy', + 'pidfile' => '/var/run/haproxy.pid', + 'maxconn' => '4000', + 'user' => 'haproxy', + 'group' => 'haproxy', + 'daemon' => '', + 'stats' => 'socket /var/lib/haproxy/stats' + } + $defaults_options = { + 'log' => 'global', + 'stats' => 'enable', + 'option' => 'redispatch', + 'retries' => '3', + 'timeout' => [ + 'http-request 10s', + 'queue 1m', + 'connect 10s', + 'client 1m', + 'server 1m', + 'check 10s', + ], + 'maxconn' => '8000' + } + } + default: { fail("The $::osfamily operating system is not supported with the haproxy module") } + } +} diff --git a/spec/defines/config_spec.rb b/spec/defines/config_spec.rb deleted file mode 100644 index 6a1af44..0000000 --- a/spec/defines/config_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'spec_helper' - -describe 'haproxy::config' do - let(:title) { 'tyler' } - let(:facts) {{ :ipaddress => '1.1.1.1' }} - context "when only one port is provided" do - let(:params) do - { :name => 'croy', - :ports => '18140' - } - end - - it { should contain_concat__fragment('croy_config_block').with( - 'order' => '20', - 'target' => '/etc/haproxy/haproxy.cfg', - 'content' => "\nlisten croy 1.1.1.1:18140\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n" - ) } - end - context "when an array of ports is provided" do - let(:params) do - { :name => 'apache', - :listen_ip => '23.23.23.23', - :ports => [ - '80', - '443', - ] - } - end - - it { should contain_concat__fragment('apache_config_block').with( - 'order' => '20', - 'target' => '/etc/haproxy/haproxy.cfg', - 'content' => "\nlisten apache 23.23.23.23:80,23.23.23.23:443\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n" - ) } - end -end diff --git a/spec/defines/listen_spec.rb b/spec/defines/listen_spec.rb new file mode 100644 index 0000000..c4539b8 --- /dev/null +++ b/spec/defines/listen_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe 'haproxy::listen' do + let(:title) { 'tyler' } + let(:facts) {{ :ipaddress => '1.1.1.1' }} + context "when only one port is provided" do + let(:params) do + { :name => 'croy', + :ports => '18140' + } + end + + it { should contain_concat__fragment('croy_listen_block').with( + 'order' => '20', + 'target' => '/etc/haproxy/haproxy.cfg', + 'content' => "\nlisten croy 1.1.1.1:18140\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n" + ) } + end + context "when an array of ports is provided" do + let(:params) do + { :name => 'apache', + :ipaddress => '23.23.23.23', + :ports => [ + '80', + '443', + ] + } + end + + it { should contain_concat__fragment('apache_listen_block').with( + 'order' => '20', + 'target' => '/etc/haproxy/haproxy.cfg', + 'content' => "\nlisten apache 23.23.23.23:80,23.23.23.23:443\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n" + ) } + end +end diff --git a/templates/haproxy-base.cfg.erb b/templates/haproxy-base.cfg.erb index 3e21436..42e791c 100644 --- a/templates/haproxy-base.cfg.erb +++ b/templates/haproxy-base.cfg.erb @@ -1,5 +1,5 @@ global -<% haproxy_global_options.sort.each do |key,val| -%> +<% global_options.sort.each do |key,val| -%> <% if val.is_a?(Array) -%> <% val.each do |item| -%> <%= key %> <%= item %> @@ -10,7 +10,7 @@ global <% end -%> defaults -<% haproxy_defaults_options.sort.each do |key,val| -%> +<% defaults_options.sort.each do |key,val| -%> <% if val.is_a?(Array) -%> <% val.each do |item| -%> <%= key %> <%= item %> @@ -18,4 +18,4 @@ defaults <% else -%> <%= key %> <%= val %> <% end -%> -<% end -%> \ No newline at end of file +<% end -%> diff --git a/templates/haproxy_config_block.erb b/templates/haproxy_config_block.erb deleted file mode 100644 index 9223140..0000000 --- a/templates/haproxy_config_block.erb +++ /dev/null @@ -1,11 +0,0 @@ - -listen <%= name %> <%= listen_ip %>:<%= Array(ports).join(",#{listen_ip}:") %> -<% config_options.sort.each do |key, val| -%> -<% if val.is_a?(Array) -%> -<% val.each do |item| -%> - <%= key %> <%= item %> -<% end -%> -<% else -%> - <%= key %> <%= val %> -<% end -%> -<% end -%> diff --git a/templates/haproxy_listen_block.erb b/templates/haproxy_listen_block.erb new file mode 100644 index 0000000..66abf1f --- /dev/null +++ b/templates/haproxy_listen_block.erb @@ -0,0 +1,11 @@ + +listen <%= name %> <%= ipaddress %>:<%= Array(ports).join(",#{ipaddress}:") %> +<% options.sort.each do |key, val| -%> +<% if val.is_a?(Array) -%> +<% val.each do |item| -%> + <%= key %> <%= item %> +<% end -%> +<% else -%> + <%= key %> <%= val %> +<% end -%> +<% end -%> diff --git a/tests/init.pp b/tests/init.pp index f27f809..77590ac 100644 --- a/tests/init.pp +++ b/tests/init.pp @@ -1,31 +1,35 @@ # Declare haproxy base class with configuration options class { 'haproxy': - enable => true, - haproxy_global_options => {'log' => "${::ipaddress} local0", - 'chroot' => '/var/lib/haproxy', - 'pidfile' => '/var/run/haproxy.pid', - 'maxconn' => '4000', - 'user' => 'haproxy', - 'group' => 'haproxy', - 'daemon' => '', - 'stats' => 'socket /var/lib/haproxy/stats' - }, - haproxy_defaults_options => {'log' => 'global', - 'stats' => 'enable', - 'option' => 'redispatch', - 'retries' => '3', - 'timeout' => ['http-request 10s', - 'queue 1m', - 'connect 10s', - 'client 1m', - 'server 1m', - 'check 10s'], - 'maxconn' => '8000' - }, + enable => true, + global_options => { + 'log' => "${::ipaddress} local0", + 'chroot' => '/var/lib/haproxy', + 'pidfile' => '/var/run/haproxy.pid', + 'maxconn' => '4000', + 'user' => 'haproxy', + 'group' => 'haproxy', + 'daemon' => '', + 'stats' => 'socket /var/lib/haproxy/stats', + }, + defaults_options => { + 'log' => 'global', + 'stats' => 'enable', + 'option' => 'redispatch', + 'retries' => '3', + 'timeout' => [ + 'http-request 10s', + 'queue 1m', + 'connect 10s', + 'client 1m', + 'server 1m', + 'check 10s', + ], + 'maxconn' => '8000', + }, } # Export a balancermember server, note that the listening_service parameter -# will/must correlate with an haproxy::config defined resource type. +# will/must correlate with an haproxy::listen defined resource type. @@haproxy::balancermember { $fqdn: order => '21', listening_service => 'puppet00', @@ -39,18 +43,27 @@ class { 'haproxy': # Note that the balancermember server resources are being collected in # the haproxy::config defined resource type with the following line: # Haproxy::Balancermember <<| listening_service == $name |>> -haproxy::config { 'puppet00': - order => '20', - virtual_ip => $::ipaddress, - virtual_ip_port => '18140', - haproxy_config_options => { - 'option' => ['tcplog', 'ssl-hello-chk'], 'balance' => 'roundrobin' }, +haproxy::listen { 'puppet00': + order => '20', + ipaddress => $::ipaddress, + ports => '18140', + options => { + 'option' => [ + 'tcplog', + 'ssl-hello-chk', + ], + 'balance' => 'roundrobin', + }, } -haproxy::config { 'stats': - order => '30', - virtual_ip => '', - virtual_ip_port => '9090', - haproxy_config_options => { 'mode' => 'http', - 'stats' => ['uri /', 'auth puppet:puppet'] +haproxy::listen { 'stats': + order => '30', + ipaddress => '', + ports => '9090', + options => { + 'mode' => 'http', + 'stats' => [ + 'uri /', + 'auth puppet:puppet' + ], }, } -- cgit v1.2.3