Skip to content

Commit

Permalink
implement apt.conf.d purging
Browse files Browse the repository at this point in the history
this module already has parameters that let users purge sources.list.d
and preferences.d. It also has resources to create source files in
sources.list.d and "pins" in preferences.d and also has a resource to
create a configuration file in apt.conf.d. however, for some reason it
can't purge apt.conf.d

purging this directory can help users ensure that systems run exactly
with what puppet knows the system should be configured with.
  • Loading branch information
lelutin committed Jul 15, 2019
1 parent 6d0c3f5 commit 84be3a6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ APT is a package manager available on Debian, Ubuntu, and several other operatin

* Your system's `preferences` file and `preferences.d` directory
* Your system's `sources.list` file and `sources.list.d` directory
* Your system's `apt.conf.d` directory
* System repositories
* Authentication keys

**Note:** This module offers `purge` parameters which, if set to `true`, **destroy** any configuration on the node's `sources.list(.d)` and `preferences(.d)` that you haven't declared through Puppet. The default for these parameters is `false`.
**Note:** This module offers `purge` parameters which, if set to `true`, **destroy** any configuration on the node's `sources.list(.d)`, `preferences(.d)` and `apt.conf.d` that you haven't declared through Puppet. The default for these parameters is `false`.

<a id="beginning-with-apt"></a>
### Beginning with apt
Expand Down
15 changes: 15 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
String $conf_d = $apt::params::conf_d,
String $preferences = $apt::params::preferences,
String $preferences_d = $apt::params::preferences_d,
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,
) inherits apt::params {
Expand Down Expand Up @@ -180,6 +181,9 @@
if $purge['preferences.d'] {
assert_type(Boolean, $purge['preferences.d'])
}
if $purge['apt.conf.d'] {
assert_type(Boolean, $purge['apt.conf.d'])
}

$_purge = merge($::apt::purge_defaults, $purge)
$_proxy = merge($apt::proxy_defaults, $proxy)
Expand Down Expand Up @@ -258,6 +262,17 @@
notify => Class['apt::update'],
}

file { 'apt.conf.d':
ensure => directory,
path => $::apt::apt_conf_d,
owner => root,
group => root,
mode => '0644',
purge => $_purge['apt.conf.d'],
recurse => $_purge['apt.conf.d'],
notify => Class['apt::update'],
}

if $confs {
create_resources('apt::conf', $confs)
}
Expand Down
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
$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'
$confs = {}
$update = {}
Expand Down Expand Up @@ -64,6 +65,7 @@
'sources.list.d' => false,
'preferences' => false,
'preferences.d' => false,
'apt.conf.d' => false,
}

$source_key_defaults = {
Expand Down
1 change: 1 addition & 0 deletions spec/acceptance/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class { 'apt':
'sources.list.d' => true,
'preferences' => true,
'preferences.d' => true,
'apt.conf.d' => true,
},
sources => $sources,
}
Expand Down
29 changes: 28 additions & 1 deletion spec/classes/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
recurse: false,
notify: 'Class[Apt::Update]' }

apt_conf_d = { ensure: 'directory',
path: '/etc/apt/apt.conf.d',
owner: 'root',
group: 'root',
mode: '0644',
purge: false,
recurse: false,
notify: 'Class[Apt::Update]' }

describe 'apt' do
let(:facts) do
{
Expand Down Expand Up @@ -59,6 +68,10 @@
is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with(preferences_d)
}

it {
is_expected.to contain_file('apt.conf.d').that_notifies('Class[Apt::Update]').only_with(apt_conf_d)
}

it { is_expected.to contain_file('/etc/apt/auth.conf').with_ensure('absent') }

it 'lays down /etc/apt/apt.conf.d/15update-stamp' do
Expand Down Expand Up @@ -158,7 +171,8 @@
{
update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
purge: { 'sources.list' => false, 'sources.list.d' => false,
'preferences' => false, 'preferences.d' => false },
'preferences' => false, 'preferences.d' => false,
'apt.conf.d' => false },
}
end

Expand All @@ -180,6 +194,11 @@
recurse: false)
}

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

it {
is_expected.to contain_exec('apt_update').with(refreshonly: false,
timeout: 1,
Expand Down Expand Up @@ -509,5 +528,13 @@
is_expected.to raise_error(Puppet::Error)
end
end

context "with purge['apt.conf.d']=>'banana'" do
let(:params) { { purge: { 'apt.conf.d' => 'banana' } } }

it do
is_expected.to raise_error(Puppet::Error)
end
end
end
end

0 comments on commit 84be3a6

Please sign in to comment.