(#14308) Add ensure=>absent for define resource.
Several apt::* define resource type does not support ensurable. This update allows ensure=>absent to support the removal of these configuration files. * apt::conf * apt::pin * apt::source
This commit is contained in:
parent
7bf6d833ed
commit
effb3f7ff3
6 changed files with 51 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
|||
define apt::conf (
|
||||
$ensure = present,
|
||||
$priority = '50',
|
||||
$content
|
||||
) {
|
||||
|
@ -8,7 +9,7 @@ define apt::conf (
|
|||
$apt_conf_d = $apt::params::apt_conf_d
|
||||
|
||||
file { "${apt_conf_d}/${priority}${name}":
|
||||
ensure => file,
|
||||
ensure => $ensure,
|
||||
content => $content,
|
||||
owner => root,
|
||||
group => root,
|
||||
|
|
|
@ -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 @@ define apt::pin(
|
|||
$preferences_d = $apt::params::preferences_d
|
||||
|
||||
file { "${name}.pref":
|
||||
ensure => file,
|
||||
ensure => $ensure,
|
||||
path => "${preferences_d}/${name}",
|
||||
owner => root,
|
||||
group => root,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# add an apt source
|
||||
|
||||
define apt::source(
|
||||
$ensure = present,
|
||||
$location = '',
|
||||
$release = $lsbdistcodename,
|
||||
$repos = 'main',
|
||||
|
@ -24,7 +25,7 @@ define apt::source(
|
|||
}
|
||||
|
||||
file { "${name}.list":
|
||||
ensure => file,
|
||||
ensure => $ensure,
|
||||
path => "${sources_list_d}/${name}.list",
|
||||
owner => root,
|
||||
group => root,
|
||||
|
@ -32,7 +33,7 @@ define apt::source(
|
|||
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 @@ define apt::source(
|
|||
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 @@ define apt::source(
|
|||
}
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
@ -23,7 +23,7 @@ describe 'apt::conf', :type => :define do
|
|||
}
|
||||
|
||||
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 @@ describe 'apt::conf', :type => :define do
|
|||
})
|
||||
}
|
||||
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
|
||||
|
|
|
@ -4,13 +4,19 @@ describe 'apt::pin', :type => :define do
|
|||
|
||||
let :default_params do
|
||||
{
|
||||
:ensure => 'present',
|
||||
:packages => '*',
|
||||
:priority => '0'
|
||||
}
|
||||
end
|
||||
|
||||
[{},
|
||||
{
|
||||
[ {},
|
||||
{
|
||||
:packages => 'apache',
|
||||
:priority => '1'
|
||||
},
|
||||
{
|
||||
:ensure => 'absent',
|
||||
:packages => 'apache',
|
||||
:priority => '1'
|
||||
}
|
||||
|
@ -27,7 +33,7 @@ describe 'apt::pin', :type => :define do
|
|||
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',
|
||||
|
|
|
@ -6,6 +6,7 @@ describe 'apt::source', :type => :define do
|
|||
|
||||
let :default_params do
|
||||
{
|
||||
:ensure => 'present',
|
||||
:location => '',
|
||||
:release => 'karmic',
|
||||
:repos => 'main',
|
||||
|
@ -35,6 +36,12 @@ describe 'apt::source', :type => :define do
|
|||
: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 @@ describe 'apt::source', :type => :define do
|
|||
it { should contain_apt__params }
|
||||
|
||||
it { should contain_file("#{title}.list").with({
|
||||
'ensure' => 'file',
|
||||
'ensure' => param_hash[:ensure],
|
||||
'path' => filename,
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
|
|
Loading…
Reference in a new issue