feat: add consul server profile

- install/configure consul
- install/configure dnsmasq as dns proxy for consul
- add unkin yumrepo definition as source for consul
- update datavol to ensure the /data volume is mounted
This commit is contained in:
2024-02-10 23:50:13 +11:00
parent 6b11ea09c7
commit 8cb6b68b53
12 changed files with 191 additions and 1 deletions
+2 -1
View File
@@ -11,6 +11,7 @@
#
class profiles::base::datavol (
Enum['present', 'absent'] $ensure = 'present',
Enum['present', 'absent', 'mounted'] $mountstate = 'mounted',
Enum['ext2', 'ext3', 'ext4', 'xfs', 'btrfs'] $fstype = 'xfs',
String $vg = 'datavg',
String $pv = '/dev/vdb',
@@ -63,7 +64,7 @@ class profiles::base::datavol (
# Ensure the logical volume is mounted at the desired location
mount { $mount:
ensure => $ensure,
ensure => $mountstate,
device => "/dev/${vg}/${lv}",
fstype => $fstype,
options => $mount_options.join(','),
+125
View File
@@ -0,0 +1,125 @@
# profiles::consul::server
class profiles::consul::server (
String $gossip_key,
String $primary_datacenter,
Hash $acl,
Hash $ports,
Hash $addresses,
Boolean $members_lookup = false,
String $members_role = undef,
Array $consul_servers = [],
Boolean $enable_ui = true,
Boolean $enable_ui_config = true,
Boolean $manage_repo = false,
String $package_ensure = 'latest',
String $package_name = 'consul',
Integer $bootstrap_count = 1,
String $domain = 'consul',
Integer $raft_multiplier = 1,
Enum[
'allow',
'deny',
'extend-cache',
'async-cache'
] $acl_down_policy = 'extend-cache',
Enum[
'allow',
'deny'
] $acl_default_policy = 'deny',
Enum[
'url',
'package',
'docker',
'none'
] $install_method = 'package',
Stdlib::IP::Address $client_addr = '0.0.0.0',
Stdlib::Absolutepath $data_dir = '/opt/consul',
Stdlib::Absolutepath $bin_dir = '/usr/bin',
Boolean $disable_remote_exec = true,
Boolean $disable_update_check = true,
) {
# set a datacentre/cluster name
$consul_cluster = "${::facts['country']}-${::facts['region']}"
# if lookup is enabled, find all the hosts in the specified role and create the servers_array
if $members_lookup {
# check that the role is also set
unless !($members_role == undef) {
fail("members_role must be provided for ${title} when members_lookup is True")
}
# if it is, find hosts, sort them so they dont cause changes every run
$servers_array = sort(query_nodes("enc_role='${members_role}' and region='${::facts['region']}'", 'networking.fqdn'))
# else use provided array from params
}else{
$servers_array = $consul_servers
}
# if $data_dir starts with /data, ensure the data mount exists
if ($data_dir.stdlib::start_with('/data') and $::facts['mountpoints']['/data']) or ! $data_dir.stdlib::start_with('/data') {
# install consul
class { 'consul':
install_method => $install_method,
manage_repo => $manage_repo,
package_name => $package_name,
package_ensure => $package_ensure,
bin_dir => $bin_dir,
config_hash => {
'primary_datacenter' => $primary_datacenter,
'acl' => $acl,
'ports' => $ports,
'addresses' => $addresses,
'disable_remote_exec' => $disable_remote_exec,
'disable_update_check' => $disable_update_check,
'domain' => $domain,
'bootstrap_expect' => $bootstrap_count,
'client_addr' => '0.0.0.0',
'data_dir' => $data_dir,
'datacenter' => $consul_cluster,
'log_level' => 'INFO',
'node_name' => $::facts['networking']['fqdn'],
'server' => true,
'ui' => $enable_ui,
'ui_config' => { 'enabled' => $enable_ui_config },
'performance' => { 'raft_multiplier' => $raft_multiplier },
'bind_addr' => $::facts['networking']['ip'],
'advertise_addr' => $::facts['networking']['ip'],
'retry_join' => $servers_array
},
}
}
# consul before dnsmasq
if defined(Class['consul']) {
# get the dns port from the $ports hash, otherwise use the default
$dns_port = pick($ports['dns'], 8600)
# install dnsmasq
package { 'dnsmasq':
ensure => installed,
}
# create the 10-consul.conf file
file { '/etc/dnsmasq.d/10-consul.conf':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => "server=/${domain}/${::facts['networking']['ip']}#${dns_port}\n",
require => Package['dnsmasq'],
notify => Service['dnsmasq'],
}
# ensure dnsmasq service is running and enabled at boot
service { 'dnsmasq':
ensure => running,
enable => true,
subscribe => File['/etc/dnsmasq.d/10-consul.conf'], # Restart dnsmasq if the consul config changes
}
}
}
+5
View File
@@ -87,6 +87,11 @@ class profiles::yum::global (
managed_repos => $managed_repos,
}
# Setup unkin repo if included in managed_repos
class { 'profiles::yum::unkin':
managed_repos => $managed_repos,
}
# setup dnf-autoupdate
include profiles::yum::autoupdater
+23
View File
@@ -0,0 +1,23 @@
# Class: profiles::yum::unkin
class profiles::yum::unkin (
Array[String] $managed_repos,
String $baseurl,
Enum[
'daily',
'weekly',
'monthly'
] $snapshot = 'daily',
) {
$release = $facts['os']['release']['major']
$basearch = $facts['os']['architecture']
if 'unkin' in $managed_repos {
yumrepo { 'unkin':
name => 'unkin',
descr => 'unkin repository',
target => '/etc/yum.repos.d/unkin.repo',
baseurl => "${baseurl}/${::facts['os']['release']['major']}/${basearch}/os/",
gpgcheck => false,
}
}
}