Debian Codegraph @

manifests/userlist.pp

raw
1 # @summary
2 # This type will set up a userlist configuration block inside the haproxy.cfg
3 # file on an haproxy load balancer.
4 #
5 # @note
6 # See http://cbonte.github.io/haproxy-dconv/configuration-1.4.html#3.4 for more info
7 #
8 # @note
9 # Currently requires the puppetlabs/concat module on the Puppet Forge
10 #
11 #
12 # @param section_name
13 # This name goes right after the 'userlist' statement in haproxy.cfg
14 # Default: $name (the namevar of the resource).
15 #
16 # @param users
17 # An array of users in the userlist.
18 # See http://cbonte.github.io/haproxy-dconv/configuration-1.4.html#3.4-user
19 #
20 # @param groups
21 # An array of groups in the userlist.
22 # See http://cbonte.github.io/haproxy-dconv/configuration-1.4.html#3.4-group
23 #
24 # @param config_file
25 # Optional. Path of the config file where this entry will be added.
26 # Assumes that the parent directory exists.
27 # Default: $haproxy::params::config_file
28 #
29 # @param instance
30 # Optional. Defaults to 'haproxy'
31 #
32 # === Authors
33 #
34 # Jeremy Kitchen <[email protected]>
35 #
36 define haproxy::userlist (
37 Optional[Array[Variant[String, Sensitive[String]]]] $users = undef,
38 Optional[Array[String]] $groups = undef,
39 String $instance = 'haproxy',
40 String[1] $section_name = $name,
41 Optional[Stdlib::Absolutepath] $config_file = undef,
42 ) {
43 include haproxy::params
44
45 $content = epp(
46 'haproxy/haproxy_userlist_block.epp',
47 {
48 epp_users => $users,
49 epp_groups => $groups,
50 epp_section_name => $section_name,
51 },
52 )
53 # we have to unwrap here, as "concat" cannot handle Sensitive Data
54 $_content = if $content =~ Sensitive { $content.unwrap } else { $content }
55
56 if $instance == 'haproxy' {
57 $instance_name = 'haproxy'
58 $_config_file = pick($config_file, $haproxy::config_file)
59 } else {
60 $instance_name = "haproxy-${instance}"
61 $_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl))
62 }
63
64 concat::fragment { "${instance_name}-${section_name}_userlist_block":
65 order => "12-${section_name}-00",
66 target => $_config_file,
67 content => $_content,
68 }
69 }