- ensure a database, user and credential is created for each grafana node - ensure all databases for a region are included in a mariadb cluster - refine params with stdlib types
68 lines
1.7 KiB
Puppet
68 lines
1.7 KiB
Puppet
# profiles::metrics::grafana
|
|
class profiles::metrics::grafana (
|
|
Stdlib::Port $http_port = 8080,
|
|
String $app_mode = 'production',
|
|
Boolean $allow_sign_up = false,
|
|
Boolean $mysql_backend = true,
|
|
String $mysql_user = 'grafana',
|
|
String $mysql_name = 'grafana',
|
|
String $mysql_pass = fqdn_rand_string(16),
|
|
Stdlib::Host $mysql_host = '127.0.0.1',
|
|
Stdlib::Port $mysql_port = 3306,
|
|
|
|
) {
|
|
|
|
# set the fqdn
|
|
$fqdn = $::facts['networking']['fqdn']
|
|
|
|
# when using mysql backend
|
|
if $mysql_backend {
|
|
|
|
@@mysql_user { "${mysql_user}@${facts['networking']['fqdn']}":
|
|
ensure => present,
|
|
password_hash => mysql::password(fqdn_rand_string(16)),
|
|
tag => $facts['region'],
|
|
}
|
|
|
|
@@mysql_grant { "${mysql_user}@${facts['networking']['fqdn']}/${mysql_name}.*":
|
|
ensure => present,
|
|
table => "${mysql_name}.*",
|
|
user => "${mysql_user}@${facts['networking']['fqdn']}",
|
|
privileges => ['ALL'],
|
|
tag => $facts['region'],
|
|
}
|
|
|
|
$database_config = {
|
|
type => 'mysql',
|
|
host => "${mysql_host}:${mysql_port}",
|
|
name => $mysql_name,
|
|
user => $mysql_user,
|
|
password => $mysql_pass.unwrap,
|
|
}
|
|
}
|
|
|
|
# build the grafana config hash
|
|
$cfg = {
|
|
app_mode => $app_mode,
|
|
server => {
|
|
http_port => $http_port,
|
|
},
|
|
database => $database_config,
|
|
users => {
|
|
allow_sign_up => $allow_sign_up,
|
|
},
|
|
}
|
|
|
|
# deploy grafana
|
|
class { 'grafana':
|
|
cfg => $cfg,
|
|
}
|
|
|
|
# fix the package provided systemd service
|
|
systemd::unit_file { 'grafana-server.service':
|
|
content => template('profiles/metrics/grafana.service.erb'),
|
|
require => Package['grafana'],
|
|
before => Service['grafana'],
|
|
}
|
|
}
|