Merge pull request 'feat: sort ntpservers, select ntp to use' (#167) from neoloc/ntp_selection into develop

Reviewed-on: unkinben/puppet-prod#167
This commit is contained in:
Ben Vincent 2024-04-23 23:29:06 +09:30
commit 6fc0b240c1
2 changed files with 15 additions and 7 deletions

View File

@ -46,6 +46,7 @@ hiera_classes:
- timezone - timezone
profiles::ntp::client::ntp_role: 'roles::infra::ntp::server' profiles::ntp::client::ntp_role: 'roles::infra::ntp::server'
profiles::ntp::client::use_ntp: 'region'
profiles::ntp::client::peers: profiles::ntp::client::peers:
- 0.pool.ntp.org - 0.pool.ntp.org
- 1.pool.ntp.org - 1.pool.ntp.org

View File

@ -11,6 +11,11 @@ class profiles::ntp::client (
'running', 'running',
'stopped' 'stopped'
] $wait_ensure = 'running', ] $wait_ensure = 'running',
Enum[
'all',
'region',
'country'
] $use_ntp = 'all',
Boolean $client_only = true, Boolean $client_only = true,
) { ) {
@ -18,23 +23,25 @@ class profiles::ntp::client (
# through the profiles::ntp::server class. # through the profiles::ntp::server class.
if $client_only { if $client_only {
# if ntp_role is set, find all hosts matching that enc_role $ntpserver_array = $ntp_role ? {
if $ntp_role == undef { undef => $peers,
$ntpserver_array = $peers default => $use_ntp ? {
}else{ 'all' => query_nodes("enc_role='${ntp_role}'", 'networking.fqdn'),
$ntpserver_array = query_nodes("enc_role='${ntp_role}'", 'networking.fqdn') 'region' => query_nodes("enc_role='${ntp_role}' and region=${facts['region']}", 'networking.fqdn'),
'country' => query_nodes("enc_role='${ntp_role}' and country=${facts['country']}", 'networking.fqdn'),
}
} }
# Define the client configuration based on OS family # Define the client configuration based on OS family
if $facts['os']['family'] == 'RedHat' { if $facts['os']['family'] == 'RedHat' {
class { 'chrony': class { 'chrony':
servers => $ntpserver_array, servers => sort($ntpserver_array),
wait_enable => $wait_enable, wait_enable => $wait_enable,
wait_ensure => $wait_ensure, wait_ensure => $wait_ensure,
} }
} else { } else {
class { 'chrony': class { 'chrony':
servers => $ntpserver_array, servers => sort($ntpserver_array),
} }
} }
} }