Puppet Class: psick::keepalived
- Defined in:
- manifests/keepalived.pp
Overview
starting point for the keepalived-psick
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'manifests/keepalived.pp', line 2
class psick::keepalived (
Enum['present','absent'] $ensure = 'present',
Variant[String[1],Undef] $config_dir_source = undef,
String $config_file_template = 'psick/keepalived/keepalived.conf.erb',
) {
$options_default = {
'notification_email_from' => "info@${::domain}",
'smtp_server' => 'localhost',
'smtp_connect_timeout' => '30',
'lvs_id' => $::hostname,
}
$options_user=hiera_hash('psick::keepalived::options', {} )
$options=merge($options_default,$options_user)
# Install package
::tp::install { 'keepalived':
ensure => $ensure,
}
# fill out given tpl, only if empty sting for tpl is given - nothing will be written
# otherwise the default tpl will be used
if $config_file_template != '' {
::tp::conf { 'keepalived':
ensure => $ensure,
template => $config_file_template,
options_hash => $options,
}
}
# ensure that the subdir for the balanced services is existing
# example: psick::keepalived::config_dir_source: "puppet:///modules/psick/keepalived/services/"
::tp::dir { 'keepalived::services':
ensure => $ensure,
path => '/etc/keepalived/services',
source => $config_dir_source,
}
# get entries from given hiera_array-KEY and for each entry:
# split vs to get role to find correct mapping in hieradata for the configured role-loadbalancing-variables like
# vip, vip_mask and options
# write File for vrrp_instance via given function
$virtualservers=hiera_array('virtualservers', [] )
$virtualservers.each | String $vs | {
$vs_split=split($vs,'-')
$app_role=$vs_split[1]
$server_role=getvar("::psick::${app_role}_server")
psick::keepalived::vrrp { $vs:
ensure => $ensure,
vip => $server_role['vip'],
vip_mask => pick($server_role['vip_mask'],'/32'),
user_options => $options,
}
# for each configured port
# write File virtual_server-port.conf via given function
if $server_role['port'] =~ Iterable {
$server_role['port'].each | String $port_type , Integer $port | {
psick::keepalived::vs { "${vs}-${port}":
ensure => $ensure,
vip => $server_role['vip'],
vip_port => $port,
user_options => $options,
}
}
}
}
# collect fragement which has to be placed in services/<zone>-<role>-<env>-<kind>.conf
Concat::Fragment <<| tag == "lb_${::zone}-${::env}" |>>
}
|