From 74c0dc84f71851e3540cab9a82d3d6ceafef566f Mon Sep 17 00:00:00 2001 From: Niels Abspoel Date: Fri, 19 Jul 2013 18:06:19 +0200 Subject: [PATCH] update chrony for forge --- manifests/config.pp | 24 ++++++++ manifests/init.pp | 55 ++++++++++--------- manifests/install.pp | 11 ++++ manifests/params.pp | 24 ++++++++ manifests/service.pp | 22 ++++++++ ...ony.conf.erb => chrony.conf.archlinux.erb} | 0 templates/chrony.keys.archlinux.erb | 1 + tests/init.pp | 11 ++++ 8 files changed, 122 insertions(+), 26 deletions(-) create mode 100644 manifests/config.pp create mode 100644 manifests/install.pp create mode 100644 manifests/params.pp create mode 100644 manifests/service.pp rename templates/{chrony.conf.erb => chrony.conf.archlinux.erb} (100%) create mode 100644 templates/chrony.keys.archlinux.erb create mode 100644 tests/init.pp diff --git a/manifests/config.pp b/manifests/config.pp new file mode 100644 index 0000000..a0231d8 --- /dev/null +++ b/manifests/config.pp @@ -0,0 +1,24 @@ +class chrony::config ( + $config = $chrony::config, + $config_template = $chrony::config_template, + $config_keys = $chrony::config_keys, + $config_keys_template = $chrony::config_keys_template, + $chrony_password = $chrony::chrony_password, + $servers = $chrony::servers,) inherits chrony { + file { $config: + ensure => file, + owner => 0, + group => 0, + mode => '0644', + content => template($config_template), + } + + file { $config_keys: + ensure => file, + owner => 0, + group => 0, + mode => '0644', + content => template($config_keys_template), + } + +} diff --git a/manifests/init.pp b/manifests/init.pp index be4dfb0..17c707d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,30 +1,33 @@ class chrony ( - $ntpservers = [ - '0.nl.pool.ntp.org', - '1.nl.pool.ntp.org', - '2.nl.pool.ntp.org', - '3.nl.pool.ntp.org', ] -){ - package { 'chrony': - ensure => present, - } + $autoupdate = $chrony::params::autoupdate, + $config = $chrony::params::config, + $config_template = $chrony::params::config_template, + $config_keys = $chrony::params::config_keys, + $config_keys_template = $chrony::params::config_keys_template, + $chrony_password = $chrony::params::chrony_password, + $package_ensure = $chrony::params::package_ensure, + $package_name = $chrony::params::package_name, + $servers = $chrony::params::servers, + $service_enable = $chrony::params::service_enable, + $service_ensure = $chrony::params::service_ensure, + $service_manage = $chrony::params::service_manage, + $service_name = $chrony::params::service_name,) inherits chrony::params { + if $autoupdate { + notice('autoupdate parameter has been deprecated and replaced with package_ensure. Set this to latest for the same behavior as autoupdate => true.' + ) + } - file { '/etc/chrony.conf': - ensure => present, - owner => root, - group => root, - mode => '0644', - content => template('chrony/chrony.conf.erb'), - require => Package['chrony'], - notify => Service['chrony.service'], - } + include '::chrony::install' + include '::chrony::config' + include '::chrony::service' + + # Anchor this as per #8140 - this ensures that classes won't float off and + # mess everything up. You can read about this at: + # http://docs.puppetlabs.com/puppet/2.7/reference/lang_containment.html#known-issues + anchor { 'chrony::begin': } + anchor { 'chrony::end': } + + Anchor['chrony::begin'] -> Class['::chrony::install'] -> Class['::chrony::config'] + ~> Class['::chrony::service'] -> Anchor['chrony::end'] - service { 'chrony.service': - ensure => running, - provider => systemd, - hasstatus => true, - hasrestart => true, - enable => true, - require => Package['chrony'], - } } diff --git a/manifests/install.pp b/manifests/install.pp new file mode 100644 index 0000000..799222d --- /dev/null +++ b/manifests/install.pp @@ -0,0 +1,11 @@ +class chrony::install ( + $package_ensure = $chrony::package_ensure, + $package_name = $chrony::package_name, +) inherits chrony { + + package { 'chrony': + ensure => $package_ensure, + name => $package_name, + } + +} diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 0000000..96be9c6 --- /dev/null +++ b/manifests/params.pp @@ -0,0 +1,24 @@ +class chrony::params { + $autoupdate = false + $package_ensure = 'present' + $service_enable = true + $service_ensure = 'running' + $service_manage = true + $chrony_password = 'xyzzy' + + case $::osfamily { + 'Archlinux' : { + $config = '/etc/chrony.conf' + $config_template = 'chrony/chrony.conf.archlinux.erb' + $config_keys = 'etc/chrony.keys' + $config_keys_template = 'chrony/chrony.keys.archlinux.erb' + $package_name = ['chrony'] + $service_name = 'chrony' + $servers = ['0.pool.ntp.org', '1.pool.ntp.org', '2.pool.ntp.org',] + } + + default : { + fail("The ${module_name} module is not supported on an ${::osfamily} based system.") + } + } +} diff --git a/manifests/service.pp b/manifests/service.pp new file mode 100644 index 0000000..cff0447 --- /dev/null +++ b/manifests/service.pp @@ -0,0 +1,22 @@ +class chrony::service ( + $service_enable = $chrony::service_enable, + $service_ensure = $chrony::service_ensure, + $service_manage = $chrony::service_manage, + $service_name = $chrony::service_name, +) inherits chrony { + + if ! ($service_ensure in [ 'running', 'stopped' ]) { + fail('service_ensure parameter must be running or stopped') + } + + if $service_manage == true { + service { 'chrony': + ensure => $service_ensure, + enable => $service_enable, + name => $service_name, + hasstatus => true, + hasrestart => true, + } + } + +} diff --git a/templates/chrony.conf.erb b/templates/chrony.conf.archlinux.erb similarity index 100% rename from templates/chrony.conf.erb rename to templates/chrony.conf.archlinux.erb diff --git a/templates/chrony.keys.archlinux.erb b/templates/chrony.keys.archlinux.erb new file mode 100644 index 0000000..d58e479 --- /dev/null +++ b/templates/chrony.keys.archlinux.erb @@ -0,0 +1 @@ +1 <%= chrony_password %> \ No newline at end of file diff --git a/tests/init.pp b/tests/init.pp new file mode 100644 index 0000000..1d7c43b --- /dev/null +++ b/tests/init.pp @@ -0,0 +1,11 @@ +node default { + + notify { 'enduser-before': } + notify { 'enduser-after': } + + class { 'chrony': + require => Notify['enduser-before'], + before => Notify['enduser-after'], + } + +}