Skip to content

Instantly share code, notes, and snippets.

@jfryman
Last active December 21, 2015 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfryman/6290603 to your computer and use it in GitHub Desktop.
Save jfryman/6290603 to your computer and use it in GitHub Desktop.
HAProxy Puppet Module Snippets
haproxy::proxy { $es_proxy_name:
proxy => 'listen',
mode => 'http',
ip => $::ipaddress_lo,
port => '9200',
config => {
balance => 'roundrobin',
},
}
haproxy::proxy::member { $es_proxy_name:
hostname => $::ec2_local_ipv4,
port => '9200',
param => [
'weight 1',
'maxconn 1000',
'check',
],
}
define haproxy::proxy(
$group = $name,
$proxy = 'listen',
$mode = undef,
$ip = undef,
$port = undef,
$server = undef,
$config = undef,
$order = '30',
$block = undef,
$anchor = undef,
) {
include stdlib
tag($group)
if $config { validate_hash($config) }
if $mode { validate_re($mode, '^(http|tcp|health)') }
if $block { validate_array($block) }
validate_re($proxy, '^(listen|backend|frontend)')
# Left this way to allow for params() in default/global cases
$config_options = $config
if $ip and $port {
$proxy_options = "${name} ${ip}:${port}"
} else {
$proxy_options = $name
}
concat::fragment { $name:
target => '/etc/haproxy/haproxy.cfg',
order => $order,
content => template('haproxy/etc/haproxy/haproxy.cfg_default-proxy.erb'),
}
# Realize any and all exported resources for this Proxy
Concat::Fragment <<| tag == $name |>>
}
define haproxy::proxy::member(
$proxy = $name,
$shortname = $::hostname,
$hostname = $::fqdn,
$port = undef,
$param = undef,
) {
include stdlib
if $param { validate_array($param) }
$server = {
"${shortname}" => {
host => $hostname,
port => $port,
param => $param,
}
}
@@concat::fragment { "${proxy}-02-member-${shortname}":
target => '/etc/haproxy/haproxy.cfg',
order => "30",
content => template('haproxy/etc/haproxy/haproxy.cfg_server.erb'),
tag => $proxy,
}
}
<%= proxy %> <%- if @proxy_options -%> <%= proxy_options %><% end %>
<%- if @mode -%>
mode <%= mode %>
<%- end -%>
<%- if @config -%>
<%= scope.function_template(['haproxy/etc/haproxy/haproxy.cfg_config.erb']) %>
<%- end -%>
<%- if @server -%>
<%= scope.function_template(['haproxy/etc/haproxy/haproxy.cfg_server.erb']) %>
<%- end -%>
<%- if @config_options -%>
<%- config_options.sort.each do |k,v| -%>
<%- if v.class == Array -%>
<%- v.each do |x| -%>
<%= k %> <%= x %>
<%- end -%>
<%- else -%>
<%= k %> <%= v %>
<%- end -%>
<%- end -%>
<%- end -%>
<%- server.each do |k,v| -%>
server <%= k %> <%= v['host'] %>:<%= v['port'] %> <% if v.has_key?('param') %><%= v['param'].join(' ') %><%- end %>
<%- end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment