diff --git a/manifests/conf.pp b/manifests/conf.pp index fa7f97d435..03aab8e002 100644 --- a/manifests/conf.pp +++ b/manifests/conf.pp @@ -1,4 +1,5 @@ define apt::conf ( + $ensure = present, $priority = '50', $content ) { @@ -8,7 +9,7 @@ $apt_conf_d = $apt::params::apt_conf_d file { "${apt_conf_d}/${priority}${name}": - ensure => file, + ensure => $ensure, content => $content, owner => root, group => root, diff --git a/manifests/pin.pp b/manifests/pin.pp index 2899fce77a..b69e230ea0 100644 --- a/manifests/pin.pp +++ b/manifests/pin.pp @@ -2,6 +2,7 @@ # pin a release in apt, useful for unstable repositories define apt::pin( + $ensure = present, $packages = '*', $priority = 0 ) { @@ -11,7 +12,7 @@ $preferences_d = $apt::params::preferences_d file { "${name}.pref": - ensure => file, + ensure => $ensure, path => "${preferences_d}/${name}", owner => root, group => root, diff --git a/manifests/source.pp b/manifests/source.pp index 17d2d8e5a2..c63fc2fb22 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -2,6 +2,7 @@ # add an apt source define apt::source( + $ensure = present, $location = '', $release = $lsbdistcodename, $repos = 'main', @@ -24,7 +25,7 @@ } file { "${name}.list": - ensure => file, + ensure => $ensure, path => "${sources_list_d}/${name}.list", owner => root, group => root, @@ -32,7 +33,7 @@ content => template("${module_name}/source.list.erb"), } - if $pin != false { + if ($pin != false) and ($ensure == 'present') { apt::pin { $release: priority => $pin, before => File["${name}.list"] @@ -45,7 +46,7 @@ refreshonly => true, } - if $required_packages != false { + if ($required_packages != false) and ($ensure == 'present') { exec { "Required packages: '${required_packages}' for ${name}": command => "${provider} -y install ${required_packages}", subscribe => File["${name}.list"], @@ -53,7 +54,8 @@ } } - if $key != false { + # We do not want to remove keys when the source is absent. + if ($key != false) and ($ensure == 'present') { apt::key { "Add key: ${key} from Apt::Source ${title}": ensure => present, key => $key, diff --git a/spec/defines/conf_spec.rb b/spec/defines/conf_spec.rb index 7c04db1c12..5a81b5148c 100644 --- a/spec/defines/conf_spec.rb +++ b/spec/defines/conf_spec.rb @@ -23,7 +23,7 @@ } it { should contain_file(filename).with({ - 'ensure' => 'file', + 'ensure' => 'present', 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n", 'owner' => 'root', 'group' => 'root', @@ -31,4 +31,27 @@ }) } end + + describe "when removing an apt preference" do + let :params do + { + :ensure => 'absent', + :priority => '00', + :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n" + } + end + + let :filename do + "/etc/apt/apt.conf.d/00norecommends" + end + + it { should contain_file(filename).with({ + 'ensure' => 'absent', + 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n", + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + }) + } + end end diff --git a/spec/defines/pin_spec.rb b/spec/defines/pin_spec.rb index dbc595c568..c5d3fd91af 100644 --- a/spec/defines/pin_spec.rb +++ b/spec/defines/pin_spec.rb @@ -4,13 +4,19 @@ let :default_params do { + :ensure => 'present', :packages => '*', :priority => '0' } end - [{}, - { + [ {}, + { + :packages => 'apache', + :priority => '1' + }, + { + :ensure => 'absent', :packages => 'apache', :priority => '1' } @@ -27,7 +33,7 @@ it { should include_class("apt::params") } it { should contain_file("#{title}.pref").with({ - 'ensure' => 'file', + 'ensure' => param_hash[:ensure], 'path' => "/etc/apt/preferences.d/#{title}", 'owner' => 'root', 'group' => 'root', diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index 284342940b..02bc45fcbe 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -6,6 +6,7 @@ let :default_params do { + :ensure => 'present', :location => '', :release => 'karmic', :repos => 'main', @@ -35,6 +36,12 @@ :key => 'key_name', :key_server => 'keyserver.debian.com', :key_content => false, + }, + { + :ensure => 'absent', + :location => 'somewhere', + :release => 'precise', + :repos => 'security', } ].each do |param_set| describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do @@ -66,7 +73,7 @@ it { should contain_apt__params } it { should contain_file("#{title}.list").with({ - 'ensure' => 'file', + 'ensure' => param_hash[:ensure], 'path' => filename, 'owner' => 'root', 'group' => 'root',