(#12522) Adding purge option to apt class
Adds a purge option to the apt class to remove repositories that are not managed by apt::source
This commit is contained in:
parent
52adc3555c
commit
8c279636f5
2 changed files with 52 additions and 17 deletions
|
@ -15,14 +15,17 @@
|
||||||
# Sample Usage:
|
# Sample Usage:
|
||||||
# class { 'apt': }
|
# class { 'apt': }
|
||||||
class apt(
|
class apt(
|
||||||
$disable_keys = false,
|
|
||||||
$always_apt_update = false,
|
$always_apt_update = false,
|
||||||
|
$disable_keys = false,
|
||||||
$proxy_host = false,
|
$proxy_host = false,
|
||||||
$proxy_port = '8080'
|
$proxy_port = '8080',
|
||||||
|
$purge = false
|
||||||
) {
|
) {
|
||||||
|
|
||||||
include apt::params
|
include apt::params
|
||||||
|
|
||||||
|
validate_bool($purge)
|
||||||
|
|
||||||
$refresh_only_apt_update = $always_apt_update? {
|
$refresh_only_apt_update = $always_apt_update? {
|
||||||
true => false,
|
true => false,
|
||||||
false => true
|
false => true
|
||||||
|
@ -36,6 +39,10 @@ class apt(
|
||||||
owner => root,
|
owner => root,
|
||||||
group => root,
|
group => root,
|
||||||
mode => 644,
|
mode => 644,
|
||||||
|
content => $purge ? {
|
||||||
|
false => undef,
|
||||||
|
true => "# Repos managed by puppet.\n",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
file { "sources.list.d":
|
file { "sources.list.d":
|
||||||
|
@ -43,6 +50,8 @@ class apt(
|
||||||
ensure => directory,
|
ensure => directory,
|
||||||
owner => root,
|
owner => root,
|
||||||
group => root,
|
group => root,
|
||||||
|
purge => $purge,
|
||||||
|
recurse => $purge,
|
||||||
}
|
}
|
||||||
|
|
||||||
exec { "apt_update":
|
exec { "apt_update":
|
||||||
|
|
|
@ -3,7 +3,8 @@ describe 'apt', :type => :class do
|
||||||
let :default_params do
|
let :default_params do
|
||||||
{
|
{
|
||||||
:disable_keys => false,
|
:disable_keys => false,
|
||||||
:always_apt_update => false
|
:always_apt_update => false,
|
||||||
|
:purge => false
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -12,7 +13,8 @@ describe 'apt', :type => :class do
|
||||||
:disable_keys => true,
|
:disable_keys => true,
|
||||||
:always_apt_update => true,
|
:always_apt_update => true,
|
||||||
:proxy_host => true,
|
:proxy_host => true,
|
||||||
:proxy_port => '3128'
|
:proxy_port => '3128',
|
||||||
|
:purge => true
|
||||||
}
|
}
|
||||||
].each do |param_set|
|
].each do |param_set|
|
||||||
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
|
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
|
||||||
|
@ -37,22 +39,46 @@ describe 'apt', :type => :class do
|
||||||
it { should contain_package("python-software-properties") }
|
it { should contain_package("python-software-properties") }
|
||||||
|
|
||||||
it {
|
it {
|
||||||
|
if param_hash[:purge]
|
||||||
should contain_file("sources.list").with({
|
should contain_file("sources.list").with({
|
||||||
'path' => "/etc/apt/sources.list",
|
'path' => "/etc/apt/sources.list",
|
||||||
'ensure' => "present",
|
'ensure' => "present",
|
||||||
'owner' => "root",
|
'owner' => "root",
|
||||||
'group' => "root",
|
'group' => "root",
|
||||||
'mode' => 644
|
'mode' => 644,
|
||||||
})
|
"content" => "# Repos managed by puppet.\n"
|
||||||
|
})
|
||||||
|
else
|
||||||
|
should contain_file("sources.list").with({
|
||||||
|
'path' => "/etc/apt/sources.list",
|
||||||
|
'ensure' => "present",
|
||||||
|
'owner' => "root",
|
||||||
|
'group' => "root",
|
||||||
|
'mode' => 644,
|
||||||
|
'content' => nil
|
||||||
|
})
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
it {
|
it {
|
||||||
should create_file("sources.list.d").with({
|
if param_hash[:purge]
|
||||||
"path" => "/etc/apt/sources.list.d",
|
should create_file("sources.list.d").with({
|
||||||
"ensure" => "directory",
|
'path' => "/etc/apt/sources.list.d",
|
||||||
"owner" => "root",
|
'ensure' => "directory",
|
||||||
"group" => "root"
|
'owner' => "root",
|
||||||
})
|
'group' => "root",
|
||||||
|
'purge' => true,
|
||||||
|
'recurse' => true
|
||||||
|
})
|
||||||
|
else
|
||||||
|
should create_file("sources.list.d").with({
|
||||||
|
'path' => "/etc/apt/sources.list.d",
|
||||||
|
'ensure' => "directory",
|
||||||
|
'owner' => "root",
|
||||||
|
'group' => "root",
|
||||||
|
'purge' => false,
|
||||||
|
'recurse' => false
|
||||||
|
})
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
it {
|
it {
|
||||||
|
|
Loading…
Reference in a new issue