diff --git a/hieradata/common.yaml b/hieradata/common.yaml index 185780a..2781951 100644 --- a/hieradata/common.yaml +++ b/hieradata/common.yaml @@ -46,6 +46,7 @@ hiera_classes: - timezone profiles::ntp::client::ntp_role: 'roles::infra::ntp::server' +profiles::ntp::client::use_ntp: 'region' profiles::ntp::client::peers: - 0.pool.ntp.org - 1.pool.ntp.org diff --git a/site/profiles/manifests/ntp/client.pp b/site/profiles/manifests/ntp/client.pp index e3c90a7..c09cff2 100644 --- a/site/profiles/manifests/ntp/client.pp +++ b/site/profiles/manifests/ntp/client.pp @@ -11,6 +11,11 @@ class profiles::ntp::client ( 'running', 'stopped' ] $wait_ensure = 'running', + Enum[ + 'all', + 'region', + 'country' + ] $use_ntp = 'all', Boolean $client_only = true, ) { @@ -18,23 +23,25 @@ class profiles::ntp::client ( # through the profiles::ntp::server class. if $client_only { - # if ntp_role is set, find all hosts matching that enc_role - if $ntp_role == undef { - $ntpserver_array = $peers - }else{ - $ntpserver_array = query_nodes("enc_role='${ntp_role}'", 'networking.fqdn') + $ntpserver_array = $ntp_role ? { + undef => $peers, + default => $use_ntp ? { + 'all' => 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 if $facts['os']['family'] == 'RedHat' { class { 'chrony': - servers => $ntpserver_array, + servers => sort($ntpserver_array), wait_enable => $wait_enable, wait_ensure => $wait_ensure, } } else { class { 'chrony': - servers => $ntpserver_array, + servers => sort($ntpserver_array), } } }