Ubuntu - Preload Answers to Apt Install

Whenever I install a package on a server I always create a bash provisioning script of the process so I can easily reproduce the installation in the future.

One of the roadblocks you may run into while attempting to script an install is answering prompted questions for the install.

Luckily Ubuntu/Debian has a tool to let you store preconfigured answers to those prompts so the process can be completely automated.

The question however I find myself asking however is, what are the variable names that I am allowed to preconfigure so I can preload them.

debconf-get-selections to the rescue!

sudo debconf-get-selections | grep mysql-server  


mysql-server    mysql-server/root_password  password  
mysql-server    mysql-server/root_password_again    password  

So now that I know some of the prompt variable names, I can preload those values with my bash script with the following bits of code:

debconf-set-selections <<< "mysql-server mysql-server/root_password password $DBPASSWD"  
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $DBPASSWD"  

The only downside I have found is that you must first install the package and answer the prompts so that it will populate the debconf database so you can query the selection variables to write your script.