<p>There are options you can pass through apt-get to dpkg that will handle the config choices. We usually do something like:</p>

<p><code>apt-get install -y --no_install_recommends -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' &lt;package_name&gt;</code></p>

<p>When using ansible you can do:</p>

<pre><code>  apt:
    pkg: "{{ item }}"
    only_upgrade: yes
    install_recommends: no
    force: yes
    dpkg_options: 'force-confdef,force-confold'
    state: latest
  with_items:
    - &lt;package_name&gt;
</code></pre>

<p>For further details on the ansible <strong>apt</strong> module options look <a href="https://docs.ansible.com/ansible/latest/modules/apt_module.html" rel="noreferrer">here</a></p>

CC BY-SA 4.0
2022-02-10T09:51:58.370Z
Would be nice if you could explain or link to an explanation of the flags you provided :) in this case the dpkg manpage: https://www.man7.org/linux/man-pages/man1/dpkg.1.html
xeruf
CC BY-SA 4.0
2018-09-06T08:21:46.777Z
2018-09-06T08:21:46.777Z
Jiri Klouda
<p>When performing and <code>apt-get update; apt-get upgrade -y</code> on a server I encountered the message:</p>

<pre><code>Setting up sudo (1.8.16-0ubuntu1.5) ...

Configuration file '/etc/sudoers'
==&gt; Modified (by you or by a script) since installation.
==&gt; 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) ...
</code></pre>

<p>I know that <code>debconf</code> can be used to configure packages, like MySQL, to answer questions to prompts.</p>

<p>Which Linux Program/Module/Function/etc should I use to prepare an answer to this prompt? </p>

<p>I would really like to know a solution that be performed via Ansilbe if one exists. In addition to a BASH script.</p>

<p>Please note: ALL my distributions are done via IaC and thus automation is critical.</p>

<ansible><linux><automation><bash>
How to keep configuration files automatically during apt-get upgrade or install?
Steven K7FAQ
# How to keep configuration files automatically during apt-get upgrade or install?

(Asked by: username_0 on 2018-09-05)

When performing and apt-get update; apt-get upgrade -y on a server I encountered the message:
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) ...

I know that debconf can be used to configure packages, like MySQL, to answer questions to prompts.
Which Linux Program/Module/Function/etc should I use to prepare an answer to this prompt? 
I would really like to know a solution that be performed via Ansilbe if one exists. In addition to a BASH script.
Please note: ALL my distributions are done via IaC and thus automation is critical.

**Tags:** ansible, linux, automation, bash


---

## 1 answers

### Answer by username_1 on 2018-09-06. Score: 17 | Accepted answer

There are options you can pass through apt-get to dpkg that will handle the config choices. We usually do something like:
apt-get install -y --no_install_recommends -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' 
When using ansible you can do:
  apt:
    pkg: "{{ item }}"
    only_upgrade: yes
    install_recommends: no
    force: yes
    dpkg_options: 'force-confdef,force-confold'
    state: latest
  with_items:
    - 

For further details on the ansible apt module options look here

> **Comments:**
> **username_2**: Would be nice if you could explain or link to an explanation of the flags you provided :) in this case the dpkg manpage: https://www.man7.org/linux/man-pages/man1/dpkg.1.html  

---

