From 09af3e051b2fd063b91ce901295e81bd2d143302 Mon Sep 17 00:00:00 2001
From: "A. Karl Kornel" <akkornel@stanford.edu>
Date: Fri, 9 Sep 2016 12:48:31 -0700
Subject: [PATCH] os::debian: Modify sources file last
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Hold off on modifying the main sources file until
we’ve created all our other sources files.
---
 manifests/os/debian.pp | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/manifests/os/debian.pp b/manifests/os/debian.pp
index 5d8f68a..a233519 100644
--- a/manifests/os/debian.pp
+++ b/manifests/os/debian.pp
@@ -66,10 +66,11 @@ class base::os::debian (
 
   # Install APT sources configuration.  This is generally handled via
   # templates.
+  # NOTE: We hold off on messing with the master sources list until we've
+  # created the other sources files.  We do this to ensure that a source
+  # never gets removed entirely.  Luckily, `aptitude update` doesn't error
+  # out if a source is listed multiple times.
   file {
-    '/etc/apt/sources.list':
-      content => template('base/os/sources/sources.list.erb'),
-      notify  => Exec['aptitude update'];
     '/etc/apt/sources.list.d':
       ensure  => 'directory',
       recurse => true,
@@ -81,6 +82,13 @@ class base::os::debian (
     '/etc/apt/sources.list.d/stanford.list':
       content => template('base/os/sources/stanford.list.erb'),
       notify  => Exec['aptitude update'];
+    '/etc/apt/sources.list':
+      content => template('base/os/sources/sources.list.erb'),
+      require => [
+                  File['/etc/apt/sources.list.d/backports.list'],
+                  File['/etc/apt/sources.list.d/stanford.list'],
+                 ],
+      notify  => Exec['aptitude update'];
   }
 
   # Install APT preferences.  We should never use /etc/apt/preferences
-- 
GitLab