From 5d821a823f733a35b1c803bbf934110958c9ef25 Mon Sep 17 00:00:00 2001 From: juniorsysadmin Date: Wed, 7 Jan 2015 17:17:41 +1100 Subject: [PATCH] (MODULES-1479) Add package_manage parameter Set package_manage to false on FreeBSD by default. --- README.markdown | 14 +++++++++++++- manifests/init.pp | 2 ++ manifests/install.pp | 8 ++++++-- manifests/params.pp | 5 +++++ spec/acceptance/ntp_install_spec.rb | 12 ++++++++++-- spec/classes/ntp_spec.rb | 11 ++++++++--- 6 files changed, 44 insertions(+), 8 deletions(-) diff --git a/README.markdown b/README.markdown index 446c17441..ecf78a905 100644 --- a/README.markdown +++ b/README.markdown @@ -88,6 +88,14 @@ class { '::ntp': } ``` +###I'd like to configure and run ntp, but I don't need to install it. + +```puppet +class { '::ntp': + package_manage => false, +} +``` + ###Looks great! But I'd like a different template; we need to do something unique here. ```puppet @@ -168,7 +176,11 @@ Array of trusted keys. ####`package_ensure` -Sets the ntp package to be installed. Can be set to 'present', 'latest', or a specific version. +Sets the ntp package to be installed. Can be set to 'present', 'latest', or a specific version. + +####`package_manage` + +Determines whether to manage the ntp package. Defaults to true. ####`package_name` diff --git a/manifests/init.pp b/manifests/init.pp index 2cbc462fd..409a0a605 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -12,6 +12,7 @@ $keys_requestkey = $ntp::params::keys_requestkey, $keys_trusted = $ntp::params::keys_trusted, $package_ensure = $ntp::params::package_ensure, + $package_manage = $ntp::params::package_manage, $package_name = $ntp::params::package_name, $panic = $ntp::params::panic, $preferred_servers = $ntp::params::preferred_servers, @@ -36,6 +37,7 @@ validate_re($keys_requestkey, ['^\d+$', '']) validate_array($keys_trusted) validate_string($package_ensure) + validate_bool($package_manage) validate_array($package_name) validate_bool($panic) validate_array($preferred_servers) diff --git a/manifests/install.pp b/manifests/install.pp index 237f4c1c0..49f4044bf 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,8 +1,12 @@ # class ntp::install inherits ntp { - package { $package_name: - ensure => $package_ensure, + if $package_manage { + + package { $package_name: + ensure => $package_ensure, + } + } } diff --git a/manifests/params.pp b/manifests/params.pp index f959b2e3d..550f93a40 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -28,6 +28,11 @@ $default_package_name = ['ntp'] $default_service_name = 'ntpd' + $package_manage = $::osfamily ? { + 'FreeBSD' => false, + default => true, + } + case $::osfamily { 'AIX': { $config = $default_config diff --git a/spec/acceptance/ntp_install_spec.rb b/spec/acceptance/ntp_install_spec.rb index 29aac2246..03dc80b63 100644 --- a/spec/acceptance/ntp_install_spec.rb +++ b/spec/acceptance/ntp_install_spec.rb @@ -1,5 +1,7 @@ require 'spec_helper_acceptance' +packagemanage = true + case fact('osfamily') when 'FreeBSD' packagename = 'net/ntp' @@ -30,9 +32,9 @@ end describe 'ntp::install class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - it 'installs the package' do + it 'installs the package when package_manage is set to true' do apply_manifest(%{ - class { 'ntp': } + class { 'ntp': package_manage => true } }, :catch_failures => true) end @@ -41,4 +43,10 @@ class { 'ntp': } it { should be_installed } end end + + it 'does not install the package when package_manage is set to false' do + apply_manifest(%{ + class { 'ntp': package_manage => false } + }, :catch_changes => true) + end end diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index ab7eda5ed..540462646 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -128,21 +128,26 @@ end describe "ntp::install on #{system}" do - let(:params) {{ :package_ensure => 'present', :package_name => ['ntp'], }} + let(:params) {{ :package_ensure => 'present', :package_name => ['ntp'], :package_manage => true, }} it { should contain_package('ntp').with( :ensure => 'present' )} describe 'should allow package ensure to be overridden' do - let(:params) {{ :package_ensure => 'latest', :package_name => ['ntp'] }} + let(:params) {{ :package_ensure => 'latest', :package_name => ['ntp'], :package_manage => true, }} it { should contain_package('ntp').with_ensure('latest') } end describe 'should allow the package name to be overridden' do - let(:params) {{ :package_ensure => 'present', :package_name => ['hambaby'] }} + let(:params) {{ :package_ensure => 'present', :package_name => ['hambaby'], :package_manage => true, }} it { should contain_package('hambaby') } end + + describe 'should allow the package to be unmanaged' do + let(:params) {{ :package_manage => false, :package_name => ['ntp'], }} + it { should_not contain_package('ntp') } + end end describe 'ntp::service' do