Defined Type: haproxy::instance
- Defined in:
- manifests/instance.pp
Summary
Manages haproxy permitting multiple instances to run on the same machine.Overview
template() function). Defaults to undef
Normally users use the Class, which runs a single haproxy daemon on a machine.
Currently requires the puppetlabs/concat module on the Puppet Forge and uses storeconfigs on the Puppet Server to export/collect resources from all balancer members.
When running multiple instances on one host, there must be a Service[] for each instance. One way to create the situation where Service[] works is using haproxy::instance_service. However you may want to do it some other way. For example, you may not have packages for your custom haproxy binary. Or, you may wish to use the standard haproxy package but not create links to it, or you may have different init.d scripts. In these cases, write your own puppet code that will result in Service[] working for you and do not call haproxy::instance_service.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'manifests/instance.pp', line 161
define haproxy::instance (
Variant[Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'], String[1]] $package_ensure = 'present',
Optional[String] $package_name = undef,
Variant[Enum['running', 'stopped'], Boolean] $service_ensure = 'running',
Boolean $service_manage = true,
Boolean $chroot_dir_manage = true,
Optional[String] $service_name = undef,
Optional[Hash] $global_options = undef,
Optional[Hash] $defaults_options = undef,
Optional[String] $restart_command = undef,
Optional[String] $custom_fragment = undef,
Optional[Stdlib::Absolutepath] $config_dir = undef,
Optional[Stdlib::Absolutepath] $config_file = undef,
Variant[Stdlib::Absolutepath, String] $config_validate_cmd = $haproxy::params::config_validate_cmd,
Boolean $merge_options = $haproxy::params::merge_options,
String $service_options = $haproxy::params::service_options,
String $sysconfig_options = $haproxy::params::sysconfig_options,
) {
# Since this is a 'define', we can not use 'inherts haproxy::params'.
# Therefore, we "include haproxy::params" for any parameters we need.
contain haproxy::params
$_global_options = pick($global_options, $haproxy::params::global_options)
$_defaults_options = pick($defaults_options, $haproxy::params::defaults_options)
# Determine instance_name based on:
# single-instance hosts: haproxy
# multi-instance hosts: haproxy-$title
if $title == 'haproxy' {
$instance_name = 'haproxy'
} else {
$instance_name = "haproxy-${title}"
}
# Determine config_dir and config_file:
# If config_dir defined, use it. Otherwise:
# single-instance hosts: use defaults
# multi-instance hosts: use templates
if $instance_name == 'haproxy' {
$_config_file = pick($config_file, $haproxy::params::config_file)
} else {
$_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl))
}
if $instance_name == 'haproxy' {
$_config_dir = pick($config_dir, $haproxy::params::config_dir)
} else {
$_config_dir = pick($config_dir, inline_template($haproxy::params::config_dir_tmpl))
}
$instance_service_name = pick($service_name, $instance_name)
haproxy::config { $title:
instance_name => $instance_name,
config_dir => $_config_dir,
config_file => $_config_file,
global_options => $_global_options,
defaults_options => $_defaults_options,
custom_fragment => $custom_fragment,
merge_options => $merge_options,
package_ensure => $package_ensure,
chroot_dir_manage => $chroot_dir_manage,
config_validate_cmd => $config_validate_cmd,
}
haproxy::install { $title:
package_name => $package_name,
package_ensure => $package_ensure,
}
haproxy::service { $title:
instance_name => $instance_service_name,
service_ensure => $service_ensure,
service_manage => $service_manage,
restart_command => $restart_command,
service_options => $service_options,
sysconfig_options => $sysconfig_options,
}
if $package_ensure == 'absent' or $package_ensure == 'purged' {
Haproxy::Service[$title]
-> Haproxy::Config[$title]
-> Haproxy::Install[$title]
} else {
Haproxy::Install[$title]
-> Haproxy::Config[$title]
~> Haproxy::Service[$title]
}
}
|