From 12a6d15981b4913a2e3ed370fdeb098f8744968a Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Fri, 10 Apr 2020 19:24:21 +0800 Subject: [PATCH] add laodbalancer-improved.pp --- loadbalancer-improved.pp | 102 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 loadbalancer-improved.pp diff --git a/loadbalancer-improved.pp b/loadbalancer-improved.pp new file mode 100644 index 0000000..79e9632 --- /dev/null +++ b/loadbalancer-improved.pp @@ -0,0 +1,102 @@ +class role::loadbalancer ( + Optional[String] $ports1 = '80', + Optional[String] $ports2 = undef, + Optional[String] $rule1 = 'puppet00', + Optional[String] $rule2 = undef, + Optional[String] $backendserver_name1 = '', + Optional[String] $backendserver_name2 = '', + Optional[String] $backendserver_ipaddress1 = undef, + Optional[String] $backendserver_ipaddress2 = undef, + Optional[String] $connetc_timeout = '60s', + ) { + + class { 'haproxy': + merge_options => 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 300s', + 'client 600s', + 'server 600s', + 'check 1m', + ], + 'maxconn' => '8000', + }, + } + + include ::haproxy + + haproxy::listen { $rule1 : + collect_exported => false, + ipaddress => $::ipaddress, + ports => $ports1, + } + + if $rule2 != undef + { + haproxy::listen { $rule2 : + collect_exported => false, + ipaddress => $::ipaddress, + ports => $ports2, + } + + haproxy::balancermember { 'member3' : + listening_service => $rule2, + server_names => $backendserver_name1, + ipaddresses => $backendserver_ipaddress1, + ports => $ports2, + options => 'check', + + } + + haproxy::balancermember { 'member4' : + listening_service => $rule2, + server_names => $backendserver_name2, + ipaddresses => $backendserver_ipaddress2, + ports => $ports2, + options => 'check', + } + + } + + + + + haproxy::balancermember { 'member1' : + listening_service => $rule1, + server_names => $backendserver_name1, + ipaddresses => $backendserver_ipaddress1, + ports => $ports1, + options => 'check', + + } + + haproxy::balancermember { 'member2' : + listening_service => $rule1, + server_names => $backendserver_name2, + ipaddresses => $backendserver_ipaddress2, + ports => $ports1, + options => 'check', + } + +#pending Improvement, possible areas: Array Input with multipal ports + + +}