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-10804) option to force purge source.lists file #948

Merged
merged 2 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
41 changes: 33 additions & 8 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
# @param config_files
# A hash made up of the various configuration files used by Apt.
#
# @param sources_list_force
# Specifies whether to perform force purge or delete. Default false.
#
class apt (
Hash $update_defaults = $apt::params::update_defaults,
Hash $purge_defaults = $apt::params::purge_defaults,
Expand Down Expand Up @@ -151,6 +154,7 @@
String $apt_conf_d = $apt::params::apt_conf_d,
Hash $config_files = $apt::params::config_files,
Hash $source_key_defaults = $apt::params::source_key_defaults,
Boolean $sources_list_force = $apt::params::sources_list_force,
) inherits apt::params {

if $facts['osfamily'] != 'Debian' {
Expand Down Expand Up @@ -185,6 +189,9 @@
if $purge['preferences.d'] {
assert_type(Boolean, $purge['preferences.d'])
}
if $sources_list_force {
assert_type(Boolean, $sources_list_force)
}
if $purge['apt.conf.d'] {
assert_type(Boolean, $purge['apt.conf.d'])
}
Expand All @@ -204,10 +211,27 @@
}
}

$sources_list_ensure = $_purge['sources.list'] ? {
true => absent,
default => file,
if $sources_list_force {
$sources_list_ensure = $_purge['sources.list'] ? {
true => absent,
default => file,
}
$sources_list_content = $_purge['sources.list'] ? {
true => nil,
default => undef,
}
}
else
{
$sources_list_ensure = $_purge['sources.list'] ? {
true => file,
default => file,
}
$sources_list_content = $_purge['sources.list'] ? {
true => "# Repos managed by puppet.\n",
default => undef,
}
}

$preferences_ensure = $_purge['preferences'] ? {
true => absent,
Expand All @@ -226,11 +250,12 @@
}

file { 'sources.list':
ensure => $sources_list_ensure,
path => $::apt::sources_list,
owner => root,
group => root,
notify => Class['apt::update'],
ensure => $sources_list_ensure,
path => $::apt::sources_list,
owner => root,
group => root,
content => $sources_list_content,
notify => Class['apt::update'],
}

file { 'sources.list.d':
Expand Down
45 changes: 23 additions & 22 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,29 @@
fail(translate('This module only works on Debian or derivatives like Ubuntu'))
}

$root = '/etc/apt'
$provider = '/usr/bin/apt-get'
$sources_list = "${root}/sources.list"
$sources_list_d = "${root}/sources.list.d"
$trusted_gpg_d = "${root}/trusted.gpg.d"
$conf_d = "${root}/apt.conf.d"
$preferences = "${root}/preferences"
$preferences_d = "${root}/preferences.d"
$apt_conf_d = "${root}/apt.conf.d"
$keyserver = 'keyserver.ubuntu.com'
$key_options = undef
$confs = {}
$update = {}
$purge = {}
$proxy = {}
$sources = {}
$keys = {}
$ppas = {}
$pins = {}
$settings = {}
$manage_auth_conf = true
$auth_conf_entries = []
$root = '/etc/apt'
$provider = '/usr/bin/apt-get'
$sources_list = "${root}/sources.list"
$sources_list_force = false
$sources_list_d = "${root}/sources.list.d"
$trusted_gpg_d = "${root}/trusted.gpg.d"
$conf_d = "${root}/apt.conf.d"
$preferences = "${root}/preferences"
$preferences_d = "${root}/preferences.d"
$apt_conf_d = "${root}/apt.conf.d"
$keyserver = 'keyserver.ubuntu.com'
$key_options = undef
$confs = {}
$update = {}
$purge = {}
$proxy = {}
$sources = {}
$keys = {}
$ppas = {}
$pins = {}
$settings = {}
$manage_auth_conf = true
$auth_conf_entries = []

$config_files = {
'conf' => {
Expand Down
68 changes: 68 additions & 0 deletions spec/classes/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,74 @@
}
end

context 'with lots of non-defaults' do
let :params do
{
update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
purge: { 'sources.list' => true, 'sources.list.d' => true,
'preferences' => true, 'preferences.d' => true,
'apt.conf.d' => true },
}
end

it {
is_expected.to contain_file('sources.list').with(content: "# Repos managed by puppet.\n")
}

it {
is_expected.to contain_file('sources.list.d').with(purge: true,
recurse: true)
}

it {
is_expected.to contain_file('preferences').with(ensure: 'absent')
}

it {
is_expected.to contain_file('preferences.d').with(purge: true,
recurse: true)
}

it {
is_expected.to contain_file('apt.conf.d').with(purge: true,
recurse: true)
}

it {
is_expected.to contain_exec('apt_update').with(refreshonly: false,
timeout: 1,
tries: 3)
}
end

context 'with defaults for sources_list_force' do
let :params do
{
update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
purge: { 'sources.list' => true },
sources_list_force: false,
}
end

it {
is_expected.to contain_file('sources.list').with(content: "# Repos managed by puppet.\n")
}
end

context 'with non defaults for sources_list_force' do
let :params do
{
update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
purge: { 'sources.list' => true },
sources_list_force: true,
}
end

it {
is_expected.to contain_file('sources.list').with(ensure: 'absent')
}
end

context 'with entries for /etc/apt/auth.conf' do
facts_hash = {
'Ubuntu 14.04' => {
Expand Down