implement apt.conf.d purging
authorGabriel Filion <gabster@lelutin.ca>
Mon, 15 Jul 2019 00:10:55 +0000 (20:10 -0400)
committerGabriel Filion <gabster@lelutin.ca>
Mon, 15 Jul 2019 00:13:24 +0000 (20:13 -0400)
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.

README.md
manifests/init.pp
manifests/params.pp
spec/acceptance/apt_spec.rb
spec/classes/apt_spec.rb

index a5abc0743975b42477cd38af4c7d3243a50d1150..f32f55313409754c9c31aae91a31a8cfb59dfa87 100644 (file)
--- a/README.md
+++ b/README.md
@@ -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
index d95bbe60b2225c20e9c40b236f73a22ee7d1e5e9..9c6a44b4603d17048f2a21393b16b326a887b3a6 100644 (file)
@@ -144,6 +144,7 @@ class apt (
   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 {
@@ -180,6 +181,9 @@ class apt (
   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)
@@ -258,6 +262,17 @@ class apt (
     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)
   }
index 76f06b9ed4bffa391ef7b3ed90bd9d74497cfc9a..65219fef5a7a65967a20a4ceff313641115b739a 100644 (file)
@@ -16,6 +16,7 @@ class apt::params {
   $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         = {}
@@ -64,6 +65,7 @@ class apt::params {
     'sources.list.d' => false,
     'preferences'    => false,
     'preferences.d'  => false,
+    'apt.conf.d'     => false,
   }
 
   $source_key_defaults = {
index d3215a17714b1765bbd05998a8a0d163db66ef16..f6f3d1d827b26950091536ad2ba29209c4dd90c3 100644 (file)
@@ -23,6 +23,7 @@ everything_everything_pp = <<-MANIFEST
           'sources.list.d' => true,
           'preferences'    => true,
           'preferences.d'  => true,
+          'apt.conf.d'     => true,
         },
         sources => $sources,
       }
index e766c00d4321a0a75635249b5b023c66e26f2066..f015185b6e664164b0fd10ca68105c1607817cb3 100644 (file)
@@ -32,6 +32,15 @@ preferences_d = { ensure: 'directory',
                   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
     {
@@ -59,6 +68,10 @@ describe 'apt' do
       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
@@ -158,7 +171,8 @@ describe 'apt' do
       {
         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
 
@@ -180,6 +194,11 @@ describe 'apt' do
                                                         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,
@@ -509,5 +528,13 @@ machine apt.example.com login aptlogin password supersecret
         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