-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.pp
More file actions
164 lines (149 loc) · 4.94 KB
/
init.pp
File metadata and controls
164 lines (149 loc) · 4.94 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Copyright 2018 dhtech
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file
#
# == Class: grafana
#
# Grafana dashboards
#
# Installing Grafana via APT, see http://docs.grafana.org/installation/debian/
# for package details such as default paths etc.
#
class grafana($current_event, $prometheus_servers = [], $akvorado_servers = []) {
# Adding the apt repository
package { 'apt-transport-https':
ensure => installed,
}
package { 'gnupg':
ensure => installed,
}
file { 'grafana-source-add':
ensure => file,
path => '/etc/apt/sources.list.d/grafana.list',
content => 'deb https://packages.grafana.com/oss/deb stable main',
notify => Exec['grafana-source-key'],
}
exec { 'grafana-source-key':
command => '/usr/bin/curl https://packages.grafana.com/gpg.key | sudo apt-key add -',
logoutput => 'on_failure',
try_sleep => 1,
refreshonly => true,
notify => Exec['grafana-source-update'],
}
exec { 'grafana-source-update':
command => '/usr/bin/apt-get update',
logoutput => 'on_failure',
try_sleep => 1,
refreshonly => true,
}
# Installing the package
package { 'grafana':
ensure => installed,
require => [
File['grafana-source-add'],
Exec['grafana-source-key'],
Exec['grafana-source-update'],
],
}
# Installing plugins
[
'grafana-piechart-panel',
'gapit-htmlgraphics-panel',
'knightss27-weathermap-panel',
'ovhcloud-akvorado-datasource',
'netsage-sankey-panel',
].each |$plugin| {
exec { "plugin-${plugin}":
command => "/usr/sbin/grafana-cli plugins install ${plugin}",
creates => "/var/lib/grafana/plugins/${plugin}",
}
}
# LDAP integration config file
file { 'ldap.toml':
path => '/etc/grafana/ldap.toml',
content => template('grafana/ldap.toml.erb'),
mode => '0644',
require => Package['grafana'],
notify => Service['grafana-server'],
}
# Our custom config
# Note: It's a good idea to check if Grafana have added something new
# in their default config that is enabled/not commented and missing in
# our custom config.
file { 'grafana-config':
path => '/etc/grafana/grafana.ini',
content => template('grafana/grafana-config.ini.erb'),
mode => '0644',
require => Package['grafana'],
notify => Service['grafana-server'],
}
# Making sure the server is enabled and running
service { 'grafana-server':
ensure => 'running',
enable => true,
require => Package['grafana'],
}
$password_exists = vault('grafana:login')
if $password_exists == {} {
# password does not exist in vault, create it and then reset grafana admin password
exec { 'create_service_account_grafana_login':
command => '/usr/local/bin/dh-create-service-account --type grafana --product login --username admin',
notify => Exec['read_password_and_reset_grafana_password'],
}
exec { 'read_password_and_reset_grafana_password':
command => [
'/usr/local/bin/dh-create-service-account --type grafana',
"--product login --format '{password}'",
'| grafana-cli admin reset-admin-password --password-from-stdin',
].join(' '),
refreshonly => true,
}
}
# Prometheus datasource provisioning
file { 'grafana-prometheus-datasources':
path => '/etc/grafana/provisioning/datasources/prometheus.yaml',
content => template('grafana/prometheus-datasource.yaml.erb'),
mode => '0644',
require => Package['grafana'],
notify => Service['grafana-server'],
}
# Akvorado datasource provisioning
file { 'grafana-akvorado-datasources':
path => '/etc/grafana/provisioning/datasources/akvorado.yaml',
content => template('grafana/akvorado-datasource.yaml.erb'),
mode => '0644',
require => Package['grafana'],
notify => Service['grafana-server'],
}
# Stage dashboards and library panels from SVN for one-time import
file { '/var/lib/grafana/dashboards-staging':
ensure => directory,
source => "puppet:///svn/${current_event}/services/grafana/staging",
recurse => true,
owner => 'grafana',
group => 'grafana',
require => Package['grafana'],
}
file { 'grafana-import-script':
path => '/usr/local/bin/grafana-import-dashboards',
content => template('grafana/grafana-import-dashboards.py.erb'),
mode => '0755',
require => Package['grafana'],
}
# One-time import via API — flag file prevents re-import on subsequent Puppet runs
exec { 'import-grafana-dashboards':
command => '/usr/local/bin/grafana-import-dashboards',
creates => '/var/lib/grafana/.dashboards-imported',
require => [
Service['grafana-server'],
File['/var/lib/grafana/dashboards-staging'],
File['grafana-import-script'],
],
}
# Setting up the Apache proxy
apache::proxy { 'grafana-backend':
url => '/',
backend => 'http://localhost:3001/',
}
}