29

I'm trying to build an Ansible Playbook to deploy some Ubuntu 12.04 servers on Linode, but my problem seems to be an Ubuntu one. When I run different combinations of apt-get or aptitude I always get the following dialog that I have to respond to.

Package configuration dialog

I'd like this to be answered from the command line so that it doesn't interrupt the automatic deployment. Any ideas?

My current commands are below. Note that I'm trying to set DEBIAN_FRONTEND:

#!/bin/bash

echo 'DEBIAN_FRONTEND="noninteractive"' >> /etc/profile
echo 'DEBIAN_FRONTEND="noninteractive"' >> ~/.profile

source /etc/profile
source ~/.profile

# This next line is the one that pops up the dialog
sudo aptitude -y install iptables-persistent

# Need this to fix an issue with the package post-install (this works fine.)
sudo sed \
    -i 's/\(modprobe -q ip6\?table_filter\)/\1 || true/g' \
    /var/lib/dpkg/info/iptables-persistent.postinst; \
sudo aptitude install iptables-persistent
Braiam
  • 67,791
  • 32
  • 179
  • 269

5 Answers5

37

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
0

If building a Docker image:

RUN echo iptables-persistent iptables-persistent/autosave_v4 boolean true | debconf-set-selections \
  && echo iptables-persistent iptables-persistent/autosave_v6 boolean true | debconf-set-selections
RUN apt-get install -y iptables-persistent
Stephane
  • 395
0

You missed -q. Try:

sudo DEBIAN_FRONTEND=noninteractive aptitude install -y -q iptables-persistent
Germar
  • 6,377
  • 2
  • 26
  • 39
0

I think you should consider doing a debconf database to automatize all the process. This is a nonintuitive process and requires lot of work, like repackaging your own deb files, to make it work and is called "debconf preseeding".

There are several examples in the Debian wiki about how to do this:

Depending of the time and circumstances you will select one (that why I didn't go into details). Take one that seems useful, and stick with it until the end.

If you run into problems ask another question detailing what you are trying to do, and how you plan to do it.

Braiam
  • 67,791
  • 32
  • 179
  • 269
0

Minor fix/adjustment to @lorin-hochstein's Ansible-based answer to non-interactively install iptables-persistent in which the task requires the sudo-privilges to run successfully (added the become: yes line): ## Prevent iptables-persistent pckgs install dialog (debconf-set-selections) - name: prevent the iptables-peristent install dialog become: yes 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

OpenITeX
  • 123