From 0569bb6388b35e79bee9142e832347272b4bfe16 Mon Sep 17 00:00:00 2001 From: Mikael Fridh Date: Sat, 23 Feb 2013 01:17:54 +0100 Subject: ntp: fixes #19418 - allow template override This allows a template to be explicitly set. --- README.markdown | 4 ++++ manifests/init.pp | 12 +++++++++++- spec/classes/ntp_spec.rb | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 6cfa7c8..3a84185 100644 --- a/README.markdown +++ b/README.markdown @@ -71,6 +71,10 @@ This parameter is used to determine whether the ntp package will be updated auto This parameter allows you to choose whether to automatically start ntp daemon on boot. +####`template` + +This parameter allows you to explicitly override the template used. + Limitations ------------ diff --git a/manifests/init.pp b/manifests/init.pp index 543db63..08296b7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -27,6 +27,9 @@ # $enable = true # Automatically start ntp deamon on boot. # +# $template = '${module_name}/${config_tpl}' +# Override with your own explicit template. +# # Actions: # # Installs, configures, and manages the ntp service. @@ -45,6 +48,7 @@ class ntp($servers='UNSET', $ensure='running', $enable=true, $restrict=true, + $config_template=undef, $autoupdate=false ) { @@ -125,6 +129,12 @@ class ntp($servers='UNSET', } } + if ($config_template == undef) { + $template_real = "${module_name}/${config_tpl}" + } else { + $template_real = $config_template + } + package { 'ntp': ensure => $package_ensure, name => $pkg_name, @@ -135,7 +145,7 @@ class ntp($servers='UNSET', owner => 0, group => 0, mode => '0644', - content => template("${module_name}/${config_tpl}"), + content => template($template_real), require => Package[$pkg_name], } diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index 8f41a22..8561171 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -108,6 +108,12 @@ describe 'ntp' do params[:autoupdate] = true subject.should contain_package('ntp').with_ensure('latest') end + it 'should allow template to be overridden' do + params[:config_template] = 'my_ntp/ntp.conf.my' + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = ['server foobar'] + (content.split("\n") & expected_lines).should == expected_lines + end end end end -- cgit v1.2.3 From 9968350db2343272068601bf5709c2548bc73eb7 Mon Sep 17 00:00:00 2001 From: Mikael Fridh Date: Fri, 8 Mar 2013 12:38:09 +0100 Subject: fixes #19418 - missing fixtures for spec tests --- spec/classes/ntp_spec.rb | 2 +- spec/fixtures/modules/my_ntp/templates/ntp.conf.erb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/modules/my_ntp/templates/ntp.conf.erb diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index 8561171..ec07aba 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -109,7 +109,7 @@ describe 'ntp' do subject.should contain_package('ntp').with_ensure('latest') end it 'should allow template to be overridden' do - params[:config_template] = 'my_ntp/ntp.conf.my' + params[:config_template] = 'my_ntp/ntp.conf.erb' content = param_value(subject, 'file', '/etc/ntp.conf', 'content') expected_lines = ['server foobar'] (content.split("\n") & expected_lines).should == expected_lines diff --git a/spec/fixtures/modules/my_ntp/templates/ntp.conf.erb b/spec/fixtures/modules/my_ntp/templates/ntp.conf.erb new file mode 100644 index 0000000..40cf67c --- /dev/null +++ b/spec/fixtures/modules/my_ntp/templates/ntp.conf.erb @@ -0,0 +1,4 @@ +#my uber ntp config +# + +server foobar -- cgit v1.2.3