| 1 |
# @summary |
| 2 |
# Manage an HAProxy map file as documented in |
| 3 |
# https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#7.3.1-map |
| 4 |
# |
| 5 |
# @note |
| 6 |
# A map file contains one key + value per line. These key-value pairs are |
| 7 |
# specified in the `mappings` array or by additional `haproxy::mapfile::entry` |
| 8 |
# definitions. |
| 9 |
# |
| 10 |
# @param name |
| 11 |
# The namevar of the defined resource type is the filename of the map file |
| 12 |
# (without any extension), relative to the `haproxy::config_dir` directory. |
| 13 |
# A '.map' extension will be added automatically. |
| 14 |
# |
| 15 |
# @param mappings |
| 16 |
# An array of mappings for this map file. Array elements may be Hashes with a |
| 17 |
# single key-value pair each (preferably) or simple Strings. Default: `[]` |
| 18 |
# |
| 19 |
# @param ensure |
| 20 |
# The state of the underlying file resource, either 'present' or 'absent'. |
| 21 |
# Default: 'present' |
| 22 |
# |
| 23 |
# @param owner |
| 24 |
# The owner of the underlying file resource. Defaut: 'root' |
| 25 |
# |
| 26 |
# @param group |
| 27 |
# The group of the underlying file resource. Defaut: 'root' |
| 28 |
# |
| 29 |
# @param mode |
| 30 |
# The mode of the underlying file resource. Defaut: '0644' |
| 31 |
# |
| 32 |
# @param instances |
| 33 |
# Array of managed HAproxy instance names to notify (restart/reload) when the |
| 34 |
# map file is updated. This is so that the same map file can be used with |
| 35 |
# multiple HAproxy instances. Default: `[ 'haproxy' ]` |
| 36 |
# |
| 37 |
define haproxy::mapfile ( |
| 38 |
Array[Variant[String, Hash]] $mappings = [], |
| 39 |
Enum['present', 'absent'] $ensure = 'present', |
| 40 |
String $owner = 'root', |
| 41 |
String $group = 'root', |
| 42 |
String $mode = '0644', |
| 43 |
Array $instances = ['haproxy'], |
| 44 |
) { |
| 45 |
$mapfile_name = $title |
| 46 |
|
| 47 |
$_instances = flatten($instances) |
| 48 |
|
| 49 |
$_mapfile_name = "${haproxy::config_dir}/${mapfile_name}.map" |
| 50 |
|
| 51 |
concat { "haproxy_mapfile_${mapfile_name}": |
| 52 |
ensure => $ensure, |
| 53 |
owner => $owner, |
| 54 |
group => $group, |
| 55 |
mode => $mode, |
| 56 |
path => $_mapfile_name, |
| 57 |
notify => Haproxy::Service[$_instances], |
| 58 |
} |
| 59 |
|
| 60 |
$parameters = { |
| 61 |
'mappings' => $mappings, |
| 62 |
'mapfile_name' => $mapfile_name, |
| 63 |
} |
| 64 |
|
| 65 |
concat::fragment { "haproxy_mapfile_${mapfile_name}-top": |
| 66 |
target => $_mapfile_name, |
| 67 |
content => epp('haproxy/haproxy_mapfile.epp', $parameters), |
| 68 |
order => '00', |
| 69 |
} |
| 70 |
} |