59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'manifests/service.pp', line 59
define consul::service (
Optional[String[1]] $address = undef,
Array[Hash] $checks = [],
Boolean $enable_tag_override = false,
String[1] $ensure = 'present',
String[1] $id = $title,
Optional[Integer[0, 65535]] $port = undef,
String[1] $service_name = $title,
Hash $service_config_hash = {},
Array[String[1]] $tags = [],
Optional[String[1]] $token = undef,
Optional[Hash[
String[1],
Variant[
String[1],
Numeric,
Boolean,
]]] $meta = undef,
) {
include consul
consul::validate_checks($checks)
if versioncmp($consul::version, '1.0.0') >= 0 {
$override_key = 'enable_tag_override'
} else {
$override_key = 'enableTagOverride'
}
$default_config_hash = {
'id' => $id,
'name' => $service_name,
'address' => $address,
'port' => $port,
'tags' => $tags,
'checks' => $checks,
'token' => $token,
'meta' => $meta,
$override_key => $enable_tag_override,
}
$basic_hash = $default_config_hash + $service_config_hash
$service_hash = {
service => $basic_hash.filter |$key, $val| { $val =~ NotUndef },
}
$escaped_id = regsubst($id,'\/','_','G')
file { "${consul::config_dir}/service_${escaped_id}.json":
ensure => $ensure,
owner => $consul::user_real,
group => $consul::group_real,
mode => $consul::config_mode,
content => consul::sorted_json($service_hash, $consul::pretty_config, $consul::pretty_config_indent),
notify => Class['consul::reload_service'],
}
}
|