Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(MODULES-1479) Add package_manage parameter #233

Merged
merged 1 commit into from
Jan 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`

Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#
class ntp::install inherits ntp {

package { $package_name:
ensure => $package_ensure,
if $package_manage {

package { $package_name:
ensure => $package_ensure,
}

}

}
5 changes: 5 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions spec/acceptance/ntp_install_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'spec_helper_acceptance'

packagemanage = true

case fact('osfamily')
when 'FreeBSD'
packagename = 'net/ntp'
Expand Down Expand Up @@ -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

Expand All @@ -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
11 changes: 8 additions & 3 deletions spec/classes/ntp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down