This repository has been archived by the owner on Mar 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.pp
111 lines (107 loc) · 2.96 KB
/
init.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
# == Class: consular
#
# Installs Consular from a PPA and adds an Upstart definition.
#
# === Parameters
#
# [*ensure*]
# Global ensure value for Consular. Valid values are 'present' and 'absent'.
# When 'absent' is passed, the package and config will be removed and the
# service will not be managed.
#
# [*package_ensure*]
# The ensure value for the Consular package. If *ensure* is 'absent' then this
# parameter is ignored and the package is purged.
#
# [*repo_manage*]
# Whether or not to manage the repository for Consular.
#
# [*repo_source*]
# The repo source to use. Current valid values: 'ppa-jerith'.
#
# [*host*]
# The address for Consular to listen on for connections from Marathon.
#
# [*port*]
# The port for Consular to listen on for connections from Marathon.
#
# [*consul*]
# The full address to use to connect to Consul.
#
# [*marathon*]
# The full address to use to connect to Marathon.
#
# [*registration_id*]
# The registration ID to use when registering for callbacks with Marathon.
#
# [*sync_interval*]
# The number of seconds between syncs. If 0, syncing will be disabled.
#
# [*purge*]
# Whether or not to purge old Consular-registered services during syncs.
#
# [*extra_opts*]
# A hash of additional options to pass to Consular. NOTE: these options can
# override any of the above options.
# e.g. { 'timeout' => 10 }
class consular (
$ensure = 'present',
$package_ensure = 'installed',
$repo_manage = true,
$repo_source = 'ppa-jerith',
$host = $::ipaddress_lo,
$port = 7000,
$consul = "http://${::ipaddress_lo}:8500",
$marathon = "http://${::ipaddress_lo}:8080",
$registration_id = $::hostname,
$sync_interval = 0,
$purge = false,
$extra_opts = {},
) {
validate_re($ensure, '^(present|absent)$')
validate_bool($repo_manage)
validate_ip_address($host)
validate_integer($port)
validate_integer($sync_interval)
validate_bool($purge)
validate_hash($extra_opts)
$purge_flag = $purge ? {
true => 'purge',
false => 'no-purge',
}
$base_opts = {
'host' => $host,
'port' => $port,
'consul' => $consul,
'marathon' => $marathon,
'registration-id' => $registration_id,
'sync-interval' => $sync_interval,
"${purge_flag}" => '',
}
$final_opts = merge($base_opts, $extra_opts)
$_package_ensure = $ensure ? {
'present' => $package_ensure,
'absent' => 'purged',
}
class { 'consular::repo':
manage => $repo_manage,
ensure => $ensure,
source => $repo_source,
}
->
package { 'python-consular':
ensure => $_package_ensure,
}
->
file { '/etc/init/consular.conf':
ensure => $ensure,
content => template('consular/init.conf.erb'),
}
if $ensure == 'present' {
service { 'consular':
ensure => running,
}
File['/etc/init/consular.conf'] ~> Service['consular']
Package['python-consular'] ~> Service['consular']
}
}