Headless Ubuntu Package Installation

With DevOps concept in mind, I don’t normally set up a server manually anymore. I either use Puppet (Chef, Ansible) or write a quick Bash script to do the server provisioning. What happens is sometimes a package I need to install may pop up a blue GUI asking for user inputs. This is annoying as it could break my server provisioning automation. No worries – I can use debconf-set-selections(Ubuntu) to preconfigure the user inputs.

Let us use an example, today I need to add newrelic-php5 to a server provisioning script written in Bash.

First let me see if I have any preconfigured values in place for newrelic-php5:

# debconf-get-selections |grep newrelic

Good, let me go ahead and install it.

# apt-get install newrelic-php5 -y


As you can see, it asks me for newrelic license and followed by application name. After filling the details and finishing the installation, I run this command again to see if there is any preconfigured values saved in debconf database:

# debconf-get-selections |grep newrelic
newrelic-php5 newrelic-php5/5.1-deprecation note
newrelic-php5 newrelic-php5/application-name string PHP Application
newrelic-php5 newrelic-php5/license-key string xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

This time I got something. To install this package headless, since I was asked to two inputs during the installation, one for license and one for application name, all I need to do is to preseed these two values with debconf-set-selections.

Let me start it over.

First, remove the package and clean up the debconf:
# apt-get remove newrelic-php5 -y
# echo PURGE | debconf-communicate newrelic-php5

OK, let me preseed the values:
# debconf-set-selections <<< "newrelic-php5 newrelic-php5/application-name string myappname" # debconf-set-selections <<< "newrelic-php5 newrelic-php5/license-key string xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Verify they are being set:
# debconf-get-selections |grep newrelic
newrelic-php5 newrelic-php5/application-name string myappname
newrelic-php5 newrelic-php5/license-key string xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Try install it again:

# apt-get install newrelic-php5 -y

Boom. It works. Happy scripting.