在服务器上执行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)以回答提示问题。 br />
我应使用哪个Linux程序/模块/功能/等来准备此提示的答案?

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

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

#1 楼

您可以通过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>


了解更多详细信息关于apt模块的选项,请看这里