How to keep configuration files automatically during apt-get upgrade or install?
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' &lt;package_name&gt;

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:
    - &lt;package_name&gt;


For further details on the ansible apt module options look here