(main) Do not prompt on configuration file update
authorRomain Tartière <romain@blogreen.org>
Mon, 6 Sep 2021 21:31:41 +0000 (11:31 -1000)
committerRomain Tartière <romain@blogreen.org>
Mon, 6 Sep 2021 21:59:09 +0000 (11:59 -1000)
When updating configuration file, apt by default prompt the user for the
action to perform.  Since we are running in a non-interactive context,
skip these prompts:

  * `--force-confdef` ensure the configuration file is replaced by a
    newer version in the package if the previous package default
    configuration file was not modified;
  * `--force-confold` keep the configuration file as it is if it has
    been modified compared to the one shipped in the previous version of the
    package.

tasks/init.rb

index 237da9b0b66c60a1e03aa855f5edb2a2268d4f8a..86367d939629d02686d88297012026f491ff86fa 100755 (executable)
@@ -8,7 +8,13 @@ require 'puppet'
 def apt_get(action)
   cmd = ['apt-get', action]
   cmd << '-y' if ['upgrade', 'dist-upgrade', 'autoremove'].include?(action)
-  ENV['DEBIAN_FRONTEND'] = 'noninteractive' if ['upgrade', 'dist-upgrade'].include?(action)
+  if ['upgrade', 'dist-upgrade'].include?(action)
+    ENV['DEBIAN_FRONTEND'] = 'noninteractive'
+    cmd << '-o'
+    cmd << 'Dpkg::Options="--force-confdef"'
+    cmd << '-o'
+    cmd << 'Dpkg::Options="--force-confold"'
+  end
   stdout, stderr, status = Open3.capture3(*cmd)
   raise Puppet::Error, stderr if status != 0
   { status: stdout.strip }