feat: add vmcluster module (#363)
- manage vmstorage package, service and environment file - manage vmselect package, service and environment file - manage vminsert package, service and environment file - manage vmagent package, service and environment file - manage options for vmstorage, vmselect, vminsert, vmagent role Reviewed-on: #363
This commit was merged in pull request #363.
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
class vmcluster::vmagent (
|
||||
Boolean $enable = false,
|
||||
String $user = 'vmagent',
|
||||
String $group = 'vmagent',
|
||||
Boolean $manage_user = true,
|
||||
Boolean $manage_service = true,
|
||||
Array[String] $packages = ['vmagent', 'vmutils'],
|
||||
Stdlib::Absolutepath $exec_path = '/usr/bin/vmagent',
|
||||
Stdlib::Absolutepath $data_path = '/var/lib/vmagent',
|
||||
Stdlib::Absolutepath $vars_file = '/etc/default/vmagent',
|
||||
String $consul_node_token = $facts['consul_node_token'],
|
||||
Hash[String, Variant[String, Array[String]]] $options = {},
|
||||
) {
|
||||
|
||||
# if enabled, manage this service
|
||||
if $enable {
|
||||
|
||||
# install required packages
|
||||
if $packages {
|
||||
ensure_packages($packages, {ensure => 'installed'})
|
||||
}
|
||||
|
||||
# manage the user/group
|
||||
if $manage_user {
|
||||
group { $group:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
user { $user:
|
||||
ensure => present,
|
||||
shell => '/usr/sbin/nologin',
|
||||
groups => $group,
|
||||
managehome => true,
|
||||
}
|
||||
}
|
||||
|
||||
# manage directories
|
||||
file { [ $data_path ]:
|
||||
ensure => directory,
|
||||
owner => $user,
|
||||
group => $group,
|
||||
}
|
||||
|
||||
# manage environment options file
|
||||
file { $vars_file:
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => template('vmcluster/options.erb'),
|
||||
}
|
||||
|
||||
file { '/etc/vmagent':
|
||||
ensure => directory,
|
||||
}
|
||||
file { '/etc/vmagent/scrape.yaml':
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => template('vmcluster/vmagent.scrape.yaml.erb'),
|
||||
}
|
||||
|
||||
# manage the systemd service
|
||||
if $manage_service {
|
||||
|
||||
# manage the subscribed resources
|
||||
if 'tls' in $options and $options['tls'] == 'true' {
|
||||
if 'remoteWrite.tlsCertFile' in $options and 'remoteWrite.tlsKeyFile' in $options {
|
||||
# tls option AND certs listed, subscribe to the options file and certs
|
||||
$subscribe = [
|
||||
File[$vars_file],
|
||||
File[$options['remoteWrite.tlsCertFile']],
|
||||
File[$options['remoteWrite.tlsKeyFile']],
|
||||
File['/etc/vmagent/scrape.yaml']
|
||||
]
|
||||
}else{
|
||||
# tls option but no certs listed, just subscribe to the options file
|
||||
warning('TLS is enabled but remoteWrite.tlsCertFile or remoteWrite.tlsKeyFile is missing from vmagent options.')
|
||||
$subscribe = [File[$vars_file], File['/etc/vmagent/scrape.yaml']]
|
||||
}
|
||||
}else{
|
||||
# no tls option, just subscribe to the options file
|
||||
$subscribe = [File[$vars_file], File['/etc/vmagent/scrape.yaml']]
|
||||
}
|
||||
|
||||
# Use these in notifications or file resources
|
||||
systemd::unit_file { 'vmagent.service':
|
||||
content => template('vmcluster/vmagent.service.erb'),
|
||||
enable => true,
|
||||
active => true,
|
||||
subscribe => $subscribe,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
class vmcluster::vminsert (
|
||||
Boolean $enable = false,
|
||||
String $user = 'vminsert',
|
||||
String $group = 'vminsert',
|
||||
Boolean $manage_user = true,
|
||||
Boolean $manage_service = true,
|
||||
Array[String] $packages = ['vminsert', 'vmutils'],
|
||||
Stdlib::Absolutepath $exec_path = '/usr/bin/vminsert',
|
||||
Stdlib::Absolutepath $vars_file = '/etc/default/vminsert',
|
||||
Hash[String, Variant[String, Array[String]]] $options = {},
|
||||
) {
|
||||
|
||||
# if enabled, manage this service
|
||||
if $enable {
|
||||
|
||||
# install required packages
|
||||
if $packages {
|
||||
ensure_packages($packages, {ensure => 'installed'})
|
||||
}
|
||||
|
||||
# manage the user/group
|
||||
if $manage_user {
|
||||
group { $group:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
user { $user:
|
||||
ensure => present,
|
||||
shell => '/usr/sbin/nologin',
|
||||
groups => $group,
|
||||
managehome => true,
|
||||
}
|
||||
}
|
||||
|
||||
# manage environment options file
|
||||
file { $vars_file:
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => template('vmcluster/options.erb'),
|
||||
}
|
||||
|
||||
# manage the systemd service
|
||||
if $manage_service {
|
||||
|
||||
# manage the subscribed resources
|
||||
if 'tls' in $options and $options['tls'] == 'true' {
|
||||
if 'tlsCertFile' in $options and 'tlsKeyFile' in $options {
|
||||
# tls option AND certs listed, subscribe to the options file and certs
|
||||
$subscribe = [File[$vars_file],File[$options['tlsCertFile']], File[$options['tlsKeyFile']]]
|
||||
}else{
|
||||
# tls option but no certs listed, just subscribe to the options file
|
||||
warning('TLS is enabled but tlsCertFile or tlsKeyFile is missing from vminsert options.')
|
||||
$subscribe = [File[$vars_file]]
|
||||
}
|
||||
}else{
|
||||
# no tls option, just subscribe to the options file
|
||||
$subscribe = [File[$vars_file]]
|
||||
}
|
||||
|
||||
# Use these in notifications or file resources
|
||||
systemd::unit_file { 'vminsert.service':
|
||||
content => template('vmcluster/vminsert.service.erb'),
|
||||
enable => true,
|
||||
active => true,
|
||||
subscribe => $subscribe,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
class vmcluster::vmselect (
|
||||
Boolean $enable = false,
|
||||
String $user = 'vmselect',
|
||||
String $group = 'vmselect',
|
||||
Boolean $manage_user = true,
|
||||
Boolean $manage_service = true,
|
||||
Array[String] $packages = ['vmselect', 'vmutils'],
|
||||
Stdlib::Absolutepath $exec_path = '/usr/bin/vmselect',
|
||||
Stdlib::Absolutepath $data_path = '/var/lib/vmselect',
|
||||
Stdlib::Absolutepath $vars_file = '/etc/default/vmselect',
|
||||
Hash[String, Variant[String, Array[String]]] $options = {},
|
||||
) {
|
||||
|
||||
# if enabled, manage this service
|
||||
if $enable {
|
||||
|
||||
# install required packages
|
||||
if $packages {
|
||||
ensure_packages($packages, {ensure => 'installed'})
|
||||
}
|
||||
|
||||
# manage the user/group
|
||||
if $manage_user {
|
||||
group { $group:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
user { $user:
|
||||
ensure => present,
|
||||
shell => '/usr/sbin/nologin',
|
||||
groups => $group,
|
||||
managehome => true,
|
||||
}
|
||||
}
|
||||
|
||||
# manage directories
|
||||
file { [ $data_path ]:
|
||||
ensure => directory,
|
||||
owner => $user,
|
||||
group => $group,
|
||||
}
|
||||
|
||||
# manage environment options file
|
||||
file { $vars_file:
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => template('vmcluster/options.erb'),
|
||||
}
|
||||
|
||||
# manage the systemd service
|
||||
if $manage_service {
|
||||
|
||||
# manage the subscribed resources
|
||||
if 'tls' in $options and $options['tls'] == 'true' {
|
||||
if 'tlsCertFile' in $options and 'tlsKeyFile' in $options {
|
||||
# tls option AND certs listed, subscribe to the options file and certs
|
||||
$subscribe = [File[$vars_file],File[$options['tlsCertFile']], File[$options['tlsKeyFile']]]
|
||||
}else{
|
||||
# tls option but no certs listed, just subscribe to the options file
|
||||
warning('TLS is enabled but tlsCertFile or tlsKeyFile is missing from vmselect options.')
|
||||
$subscribe = [File[$vars_file]]
|
||||
}
|
||||
}else{
|
||||
# no tls option, just subscribe to the options file
|
||||
$subscribe = [File[$vars_file]]
|
||||
}
|
||||
|
||||
# Use these in notifications or file resources
|
||||
systemd::unit_file { 'vmselect.service':
|
||||
content => template('vmcluster/vmselect.service.erb'),
|
||||
enable => true,
|
||||
active => true,
|
||||
subscribe => $subscribe,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
class vmcluster::vmstorage (
|
||||
Boolean $enable = false,
|
||||
String $user = 'vmstorage',
|
||||
String $group = 'vmstorage',
|
||||
Boolean $manage_user = true,
|
||||
Boolean $manage_service = true,
|
||||
Array[String] $packages = ['vmstorage', 'vmutils'],
|
||||
Stdlib::Absolutepath $exec_path = '/usr/bin/vmstorage',
|
||||
Stdlib::Absolutepath $data_path = '/var/lib/vmstorage',
|
||||
Stdlib::Absolutepath $vars_file = '/etc/default/vmstorage',
|
||||
Hash[String, Variant[String, Array[String]]] $options = {},
|
||||
) {
|
||||
|
||||
# if enabled, manage this service
|
||||
if $enable {
|
||||
|
||||
# install required packages
|
||||
if $packages {
|
||||
ensure_packages($packages, {ensure => 'installed'})
|
||||
}
|
||||
|
||||
# manage the user/group
|
||||
if $manage_user {
|
||||
group { $group:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
user { $user:
|
||||
ensure => present,
|
||||
shell => '/usr/sbin/nologin',
|
||||
groups => $group,
|
||||
managehome => true,
|
||||
}
|
||||
}
|
||||
|
||||
# manage directories
|
||||
file { [ $data_path ]:
|
||||
ensure => directory,
|
||||
owner => $user,
|
||||
group => $group,
|
||||
}
|
||||
|
||||
# manage environment options file
|
||||
file { $vars_file:
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => template('vmcluster/options.erb'),
|
||||
}
|
||||
|
||||
# manage the systemd service
|
||||
if $manage_service {
|
||||
|
||||
# manage the subscribed resources
|
||||
if 'tls' in $options and $options['tls'] == 'true' {
|
||||
if 'tlsCertFile' in $options and 'tlsKeyFile' in $options {
|
||||
# tls option AND certs listed, subscribe to the options file and certs
|
||||
$subscribe = [File[$vars_file],File[$options['tlsCertFile']], File[$options['tlsKeyFile']]]
|
||||
}else{
|
||||
# tls option but no certs listed, just subscribe to the options file
|
||||
warning('TLS is enabled but tlsCertFile or tlsKeyFile is missing from vmstorage options.')
|
||||
$subscribe = [File[$vars_file]]
|
||||
}
|
||||
}else{
|
||||
# no tls option, just subscribe to the options file
|
||||
$subscribe = [File[$vars_file]]
|
||||
}
|
||||
|
||||
# Use these in notifications or file resources
|
||||
systemd::unit_file { 'vmstorage.service':
|
||||
content => template('vmcluster/vmstorage.service.erb'),
|
||||
enable => true,
|
||||
active => true,
|
||||
subscribe => $subscribe,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user