Smarter non-interactive installation with Preseeding

Releases of Opmantek commercial products after 19 July 2019 support a new installer feature for better non-interactive installations: answers to the installer's questions can now be preseeded before the installer is invoked.
This document describes briefly how the feature can be used to streamline product  installations and upgrades.

Introduction

When you use the existing non-interactive instalation mode (which is invoked by the -y  commandline argument), all questions and confirmations that the installer requests are answered  using the default choice. This  is sufficient for simple setups where the administrator is prepared to make adjustments post-installation, but doesn't provide sufficient flexibility for automating non-standard or more complex scenarios (e.g. an installation where different MongoDB users and passwords must be used).

Preseeding addresses this limitation: It allows you to prepare and save 'canned' answers to all installer questions, which the installer then applies automatically and non-interactively.

How Preseeding works

How to generate the preseed file

The installer itself is used to create the preseed information, which you will then want to edit with a text editor.

The argument -P  instructs the installer to report the preseedable questions in all its components and to save the preseed information in a new file; after that the installer terminates and no installation or upgrade is attempted.

Here is an example invocation which causes the preseed data to be saved in the file /tmp/preseed.txt:

$ ./opEvents-X.Y.Z.run -- -P /tmp/seedfile.txt
Verifying archive integrity... All good.
Uncompressing opEvents X.Y.Z  100%

Please note that the two hyphens before the -P  argument are absolutely required, as documented on the The Opmantek Installer page. The given path also must be an absolute path.

The preseed data produced by this operation for each question includes a comment describing what installer component poses the question (and on what line), followed by the question text itself and then the question id and the default answer (which is 'y' for yes-no questions, and an empty string for text questions).

The preseed file format

The format of a preseed file is very simple:

  • it's plain text.
  • empty lines are ignored.
  • all lines starting with a #  character are treated as commented and are ignored.
  • answers are seeded by first specifying the unique id of the question (a four character hex sequence),  some whitespace, followed by the desired answer in double quotes.

All preseedable questions are identified by a unique id tag, but you're naturally not expected to read the installer code to figure out which question has what id tag! The installer's preseed generation mode mentioned above takes care of all of this for you, and produces output like in this small example:

# setup_mongodb.pl line 106
# question "Should we try to start a local MongoDB daemon?"
993d	"y"

# setup_mongodb.pl line 157
# question "Enter your MongoDB ADMIN user for $dbserver:$port [default: $conf->{db_username}]:"
d92b	""

In the example above question 993d for setup_mongdb is primed in the affirmative, ie. setup-mongodb is allowed to start a local mongodb instance should that be required. The other question, d92b, informs setup-mongodb to use the default choice for the database admin user name (ie. the value from the default configuration file).

How to adjust a preseed file

Simply use a text editor on the preseed file (e.g. nano, vi, emacs) and change the answers you like to your preferred values.
For yes-no questions you can use 'y' and 'n'; for text question any text not containing double quotes is possible.

Here is some example non-default preseed data:

# 10-postinstall-configdiff line 8
# question "Would you like to see an overview of all changed configuration items?"
89e7    "n"

# setup_mongodb.pl line 255
# question "Enter your MongoDB ADMIN user for $dbserver:$port [default: $conf->{db_username}]:"
ade0    "someotheruser"

Here question id 89e7 is preseeded in the negative; i.e. the installer will not show the liste of automatically updated config items. The other question, id ade0 , selects a different MongoDB database user.

It is likely that you'll need to run one or two installations in an interactive fashion to determine the  relevance of the individual questions. The preseed generation mode simply lists all existing questions for adjustment, but  in practice you won't encounter some of them or only rarely.

In certain special cases you may also want to look at the actual installer and installer components' source for further enlightenment. Simply running ./opProduct-X.Y.Z.run --keep --noexec  will  unpack and not  invoke the installer; the files bin/installer  and bin/installer_hooks/*  in the resulting directory contain most of the relevant logic in perl or shell form.

How to run  the installer with a preseed file

To invoke the installer in non-interactive mode with preseeded answers, simply use the -p  argument followed by the path to the preseed file you generated earlier; e.g.

$ ../opEvents-X.Y.Z.run -- -p /tmp/preseed.txt
Verifying archive integrity... All good.
Uncompressing opEvents X.Y.Z  100%
...
Ok to proceed with installation? (preseeded answer "y" interpreted as "YES")
...

Again please note that the two hyphens before the -p argument are required.

When invoked with -p  and a parseable preseed file, the installer will  automatically answer all questions without any user interaction:

  • If the preseed file contains an answer for a particular question, then that answer is used.
  • If the preseed file doesn't contain an answer for a question, then the default answer is used ('y' for yes-no questions, an empty string for text questions).

Both the  console output and the installation log (in /usr/local/omk/install.log)  point out all preseeded and automatically answered questions as such.

Limitations and Caveats

  • Question ids are NOT guaranteed to remain fixed, and may change between releases; the questions also do differ between products.
    It is therefore strongly recommended that you (re)generate a  preseed file for each release.
  • Some questions can be asked repeatedly with different dynamic arguments, but it is only possibly to  preseed one answer for all these invocations.
    For example, question 6868, "Ok to OVERWRITE changed file $item\nor No to abort installation?" may be asked multiple times for different values of '$item'. The preseed file can only provide one answer which is then used for all of them.
  • Preseeded answers can at this time not contain the double quote character.
  • The paths given for -P  and -p  must be absolute ones, ie. /some/directory/filename.


Method of finding questions which are mistakenly not carrying a preseed value

grep -rRnP 'input_yn\s+?"[^"]*?"\s*?;' bin