diff --git a/hieradata/roles/infra/metrics/grafana.yaml b/hieradata/roles/infra/metrics/grafana.yaml new file mode 100644 index 0000000..a61c689 --- /dev/null +++ b/hieradata/roles/infra/metrics/grafana.yaml @@ -0,0 +1,2 @@ +--- +#profile::metrics::grafana diff --git a/site/profiles/manifests/metrics/grafana.pp b/site/profiles/manifests/metrics/grafana.pp new file mode 100644 index 0000000..1025589 --- /dev/null +++ b/site/profiles/manifests/metrics/grafana.pp @@ -0,0 +1,58 @@ +# profiles::metrics::grafana +class profiles::metrics::grafana ( + Integer $http_port = 8080, + String $app_mode = 'production', + Boolean $allow_sign_up = false, + Boolean $mysql_backend = true, + String $mysql_host = '127.0.0.1:3306', + String $mysql_user = 'grafana', + Sensitive $mysql_pass = 'grafana', + Sensitive $mysql_name = 'grafana', + +) { + + # set the fqdn + $fqdn = $::facts['networking']['fqdn'] + + # when using mysql backend + if $mysql_backend { + + # create a db for grafana + @@mysql::db { "mydb_${fqdn}": + user => $mysql_user, + password => $mysql_pass, + dbname => $mysql_name, + host => $fqdn, + grant => ['SELECT', 'UPDATE'], + #tag => $domain, + } + + $database_config = { + type => 'mysql', + host => $mysql_host, + name => $mysql_name, + user => $mysql_user, + password => $mysql_pass.unwrap, + } + + $sensitive_database_config = Sensitive($database_config) + } + + # build the grafana config hash + $cfg = { + app_mode => $app_mode, + server => { + http_port => $http_port, + }, + database => $sensitive_database_config, + users => { + allow_sign_up => $allow_sign_up, + }, + } + + # deploy grafana + class { 'grafana': + cfg => $cfg, + } + +} diff --git a/site/roles/manifests/infra/metrics/grafana.pp b/site/roles/manifests/infra/metrics/grafana.pp index db6f757..4d9176a 100644 --- a/site/roles/manifests/infra/metrics/grafana.pp +++ b/site/roles/manifests/infra/metrics/grafana.pp @@ -2,4 +2,5 @@ class roles::infra::metrics::grafana { include profiles::defaults include profiles::base + include profiles::metrics::grafana }