如何在apt-get升级或安装过程中自动保留配置文件?


10

apt-get update; apt-get upgrade -y服务器上执行时,我遇到了以下消息:

Setting up sudo (1.8.16-0ubuntu1.5) ...

Configuration file '/etc/sudoers'
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
The default action is to keep your current version.
*** sudoers (Y/I/N/O/D/Z) [default=N] ?
Setting up ubuntu-minimal (1.361.1) ...

我知道debconf可以用来配置软件包(如MySQL)来回答提示问题。

我应该使用哪个Linux程序/模块/功能/等来准备此提示的答案?

我真的很想知道一个通​​过Ansilbe执行的解决方案(如果存在)。除了BASH脚本。

请注意:我所有的发行都是通过IaC完成的,因此自动化至关重要。

Answers:


10

您可以通过apt-get传递给dpkg的选项来处理配置选项。我们通常会执行以下操作:

apt-get install -y --no_install_recommends -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' <package_name>

使用Ansible时,您可以执行以下操作:

  apt:
    pkg: "{{ item }}"
    only_upgrade: yes
    install_recommends: no
    force: yes
    dpkg_options: 'force-confdef,force-confold'
    state: latest
  with_items:
    - <package_name>

有关ansible进一步的细节容易模块选项看这里

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.