How can I prevent apt-get/aptitude from showing dialogs during installation?

Solution 1:

Try using debconf-set-selections to set the value before installing the package:

echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections

Or, via ansible

- name: prevent the iptables-peristent install dialog
  debconf: name=iptables-persistent question={{ item }} vtype=boolean value=true
  with_items:
  - iptables-persistent/autosave_v4
  - iptables-persistent/autosave_v6
- name: install iptables-persistent
  apt: name=iptables-persistent