Debian Codegraph @

manifests/init.pp

raw
1 # @summary
2 # A Puppet module, using storeconfigs, to model an haproxy configuration.
3 # Currently VERY limited - assumes Redhat/CentOS setup. Pull requests accepted!
4 #
5 # @note
6 #
7 # Currently requires the puppetlabs/concat module on the Puppet Forge and
8 # uses storeconfigs on the Puppet Server to export/collect resources
9 # from all balancer members.
10 #
11 #
12 # @param package_ensure
13 # Ensure the package is present (installed), absent or a specific version.
14 # Defaults to 'present'
15 #
16 # @param package_name
17 # The package name of haproxy. Defaults to 'haproxy'
18 # NOTE: haproxy::instance has a different default.
19 #
20 # @param service_ensure
21 # Chooses whether the haproxy service should be running & enabled at boot, or
22 # stopped and disabled at boot. Defaults to 'running'
23 #
24 # @param service_manage
25 # Chooses whether the haproxy service state should be managed by puppet at
26 # all. Defaults to true
27 #
28 # @param service_name
29 # The service name for haproxy. Defaults to 'haproxy'
30 # NOTE: haproxy::instance has a different default.
31 #
32 # @param service_options
33 # Contents for the `/etc/defaults/haproxy` file on Debian. Defaults to "ENABLED=1\n" on Debian, and is ignored on other systems.
34 #
35 # @param chroot_dir_manage
36 # Chooses whether the haproxy chroot directory should be managed by puppet
37 # at all. Defaults to true
38 #
39 # @param sysconfig_options
40 # Contents for the `/etc/sysconfig/haproxy` file on RedHat(-based) systems.
41 # Defaults to OPTIONS="" on RedHat(-based) systems and is ignored on others
42 #
43 # @param global_options
44 # A hash of all the haproxy global options. If you want to specify more
45 # than one option (i.e. multiple timeout or stats options), pass those
46 # options as an array and you will get a line for each of them in the
47 # resultant haproxy.cfg file.
48 #
49 # @param defaults_options
50 # A hash of all the haproxy defaults options. If you want to specify more
51 # than one option (i.e. multiple timeout or stats options), pass those
52 # options as an array and you will get a line for each of them in the
53 # resultant haproxy.cfg file.
54 #
55 # @param merge_options
56 # Whether to merge the user-supplied `global_options`/`defaults_options`
57 # hashes with their default values set in params.pp. Merging allows to change
58 # or add options without having to recreate the entire hash. Defaults to
59 # false, but will default to true in future releases.
60 #
61 # @param restart_command
62 # Command to use when restarting the on config changes.
63 # Passed directly as the <code>'restart'</code> parameter to the service resource.
64 # Defaults to undef i.e. whatever the service default is.
65 #
66 # @param custom_fragment
67 # Allows arbitrary HAProxy configuration to be passed through to support
68 # additional configuration not available via parameters, or to short-circute
69 # the defined resources such as haproxy::listen when an operater would rather
70 # just write plain configuration. Accepts a string (ie, output from the
71 # template() function). Defaults to undef
72 #
73 # @param config_dir
74 # Path to the directory in which the main configuration file `haproxy.cfg`
75 # resides. Will also be used for storing any managed map files (see
76 # `haproxy::mapfile`). Default depends on platform.
77 #
78 # @param config_file
79 # Optional. Path to the haproxy config file.
80 # Default depends on platform.
81 #
82 # @param config_validate_cmd
83 # Optional. Command used by concat validate_cmd to validate new
84 # config file concat is a valid haproxy config.
85 # Default /usr/sbin/haproxy -f % -c
86 #
87 # @param manage_config_dir
88 # Optional.
89 # @param manage_service
90 # Deprecated
91 # @param enable
92 # Deprecated
93 # @example
94 # class { 'haproxy':
95 # global_options => {
96 # 'log' => "${::ipaddress} local0",
97 # 'chroot' => '/var/lib/haproxy',
98 # 'pidfile' => '/var/run/haproxy.pid',
99 # 'maxconn' => '4000',
100 # 'user' => 'haproxy',
101 # 'group' => 'haproxy',
102 # 'daemon' => '',
103 # 'stats' => 'socket /var/lib/haproxy/stats'
104 # },
105 # defaults_options => {
106 # 'log' => 'global',
107 # 'stats' => 'enable',
108 # 'option' => 'redispatch',
109 # 'retries' => '3',
110 # 'timeout' => [
111 # 'http-request 10s',
112 # 'queue 1m',
113 # 'connect 10s',
114 # 'client 1m',
115 # 'server 1m',
116 # 'check 10s'
117 # ],
118 # 'maxconn' => '8000'
119 # },
120 # }
121 #
122 class haproxy (
123 Variant[Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'], String[1]] $package_ensure = 'present',
124 String $package_name = $haproxy::params::package_name,
125 Variant[Enum['running', 'stopped'], Boolean] $service_ensure = 'running',
126 Boolean $service_manage = true,
127 Boolean $chroot_dir_manage = true,
128 String $service_name = $haproxy::params::service_name,
129 String $service_options = $haproxy::params::service_options,
130 String $sysconfig_options = $haproxy::params::sysconfig_options,
131 Hash $global_options = $haproxy::params::global_options,
132 Hash $defaults_options = $haproxy::params::defaults_options,
133 Boolean $merge_options = $haproxy::params::merge_options,
134 Optional[String] $restart_command = undef,
135 Optional[String] $custom_fragment = undef,
136 Stdlib::Absolutepath $config_dir = $haproxy::params::config_dir,
137 Optional[Stdlib::Absolutepath] $config_file = $haproxy::params::config_file,
138 Boolean $manage_config_dir = $haproxy::params::manage_config_dir,
139 Variant[Stdlib::Absolutepath, String] $config_validate_cmd = $haproxy::params::config_validate_cmd,
140
141 # Deprecated
142 Optional[Boolean] $manage_service = undef,
143 Optional[Boolean] $enable = undef,
144 ) inherits haproxy::params {
145 # NOTE: These deprecating parameters are implemented in this class,
146 # not in haproxy::instance. haproxy::instance is new and therefore
147 # there should be no legacy code that uses these deprecated
148 # parameters.
149
150 # To support deprecating $enable
151 if $enable != undef {
152 warning('The $enable parameter is deprecated; please use service_ensure and/or package_ensure instead')
153 if $enable {
154 $_package_ensure = 'present'
155 $_service_ensure = 'running'
156 } else {
157 $_package_ensure = 'absent'
158 $_service_ensure = 'stopped'
159 }
160 } else {
161 $_package_ensure = $package_ensure
162 $_service_ensure = $service_ensure
163 }
164
165 # To support deprecating $manage_service
166 if $manage_service != undef {
167 warning('The $manage_service parameter is deprecated; please use $service_manage instead')
168 $_service_manage = $manage_service
169 } else {
170 $_service_manage = $service_manage
171 }
172
173 haproxy::instance { $title:
174 package_ensure => $_package_ensure,
175 package_name => $package_name,
176 service_ensure => $_service_ensure,
177 service_manage => $_service_manage,
178 service_name => $service_name,
179 chroot_dir_manage => $chroot_dir_manage,
180 global_options => $global_options,
181 defaults_options => $defaults_options,
182 restart_command => $restart_command,
183 custom_fragment => $custom_fragment,
184 config_dir => $config_dir,
185 config_file => $config_file,
186 merge_options => $merge_options,
187 service_options => $service_options,
188 sysconfig_options => $sysconfig_options,
189 config_validate_cmd => $config_validate_cmd,
190 }
191 }