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.
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 }