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

Add ensure parameter and make ensure => absent work. #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ Default: undef
Type: string
Default: undef

`ensure`
Set to `absent` to disable and remove packages.
Type: string
Default: present

## Limitations

Tested on:
Expand Down
29 changes: 24 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
# Required: true
# Default: undef
#
# [*ensure*]
# Set to "absent" to disable and remove packages.
# Required: false
# Default: 'present'
#
# === Examples
#
# class {'::adcli':
Expand Down Expand Up @@ -52,6 +57,10 @@
$ad_join_os = $adcli::params::ad_join_os,
$ad_join_os_version = $adcli::params::ad_join_os_version,
$ad_join_os_service_pack = $adcli::params::ad_join_os_service_pack,
Enum[
'present',
'absent'
] $ensure = $adcli::params::ensure,
) inherits adcli::params {
validate_legacy(String, 'validate_string', $ad_domain)
validate_legacy(String, 'validate_string', $ad_join_username)
Expand All @@ -63,9 +72,19 @@
validate_legacy(String, 'validate_string', $ad_join_os_version)
validate_legacy(String, 'validate_string', $ad_join_os_service_pack)

anchor { 'adcli::begin': }
-> class { '::adcli::install': }
-> class { '::adcli::join': }
-> anchor { 'adcli::end': }

case $ensure {
'present': {
anchor { 'adcli::begin': }
-> class { 'adcli::install':
ensure => $ensure,
}
-> class { 'adcli::join': }
-> anchor { 'adcli::end': }
}
default: {
class { 'adcli::install':
ensure => $ensure,
}
}
}
}
6 changes: 4 additions & 2 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#
# See README.md for more details
#
class adcli::install {
class adcli::install (
Enum['present', 'absent'] $ensure,
) {

package { 'adcli':
ensure => present,
ensure => $ensure,
}
}
2 changes: 1 addition & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$ad_join_os = undef
$ad_join_os_version = undef
$ad_join_os_service_pack = undef

$ensure = 'present'

if $::osfamily == 'RedHat' and $::operatingsystemmajrelease < '6' {
fail("Unsupported platform: puppet-adcli does not currently support RedHat ${::operatingsystemmajrelease}")
Expand Down
10 changes: 10 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
it { is_expected.to contain_package('adcli').with_ensure('present') }
it { is_expected.to contain_exec('adcli_join') }
end

context 'with ensure set to absent' do
before do
params.merge!(
:ensure => 'absent'
)
end
it { is_expected.to contain_class('adcli::install') }
it { is_expected.to contain_package('adcli').with_ensure('absent') }
end
end

describe 'on RedHat 7.2' do
Expand Down