Debian Codegraph @

manifests/config.pp

raw
1 # @summary
2 # HAProxy configuration
3 # @api private
4 define haproxy::config (
5 # lint:ignore:140chars
6 Variant[Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'], String[1]] $package_ensure,
7 String $instance_name,
8 Stdlib::Absolutepath $config_file,
9 Hash $global_options,
10 Hash $defaults_options,
11 Boolean $chroot_dir_manage,
12 Stdlib::Absolutepath $config_dir = undef,
13 Optional[String] $custom_fragment = undef,
14 Boolean $merge_options = $haproxy::merge_options,
15 Variant[Stdlib::Absolutepath, String] $config_validate_cmd = $haproxy::config_validate_cmd,
16 # lint:endignore
17 ) {
18 if $caller_module_name != $module_name {
19 fail("Use of private class ${name} by ${caller_module_name}")
20 }
21
22 if $merge_options {
23 $_global_options = $haproxy::params::global_options + $global_options
24 $_defaults_options = $haproxy::params::defaults_options + $defaults_options
25 } else {
26 $_global_options = $global_options
27 $_defaults_options = $defaults_options
28 }
29
30 if defined(Class['haproxy']) {
31 $manage_config_dir = $haproxy::manage_config_dir
32 } else {
33 $manage_config_dir = $haproxy::params::manage_config_dir
34 }
35 if $manage_config_dir {
36 if $config_dir != undef {
37 file { $config_dir:
38 ensure => directory,
39 owner => '0',
40 group => '0',
41 mode => '0755',
42 }
43 }
44 }
45
46 if $config_file != undef {
47 $_config_file = $config_file
48 } else {
49 $_config_file = $haproxy::config_file
50 }
51
52 if $package_ensure == 'absent' {
53 file { $_config_file: ensure => absent }
54 } else {
55 concat { $_config_file:
56 owner => '0',
57 group => '0',
58 mode => '0640',
59 }
60
61 Concat[$_config_file] {
62 validate_cmd => $config_validate_cmd,
63 }
64
65 # Simple Header
66 concat::fragment { "${instance_name}-00-header":
67 target => $_config_file,
68 order => '01',
69 content => "# This file is managed by Puppet\n",
70 }
71
72 $parameters = {
73 '_global_options' => $_global_options,
74 '_defaults_options' => $_defaults_options,
75 'custom_fragment' => $custom_fragment,
76 }
77
78 # Template uses $_global_options, $_defaults_options, $custom_fragment
79 concat::fragment { "${instance_name}-haproxy-base":
80 target => $_config_file,
81 order => '10',
82 content => epp("${module_name}/haproxy-base.cfg.epp", $parameters),
83 }
84 }
85
86 if $chroot_dir_manage {
87 if $_global_options['chroot'] {
88 file { $_global_options['chroot']:
89 ensure => directory,
90 owner => $_global_options['user'],
91 group => $_global_options['group'],
92 }
93 }
94 }
95 }