How to Fix “dpkg-reconfigure: unable to re-open stdin” Error in Ubuntu Provisioning Scripts


2 views

When automating Ubuntu server provisioning (particularly in Vagrant environments), you might encounter this warning during package installation:

sudo apt-get -y install php5-xsl graphviz php-pear unison
...
dpkg-reconfigure: unable to re-open stdin: No file or directory

This typically occurs when:
1. Running non-interactive installations (-y flag)
2. Using provisioning tools like Vagrant/Packer
3. The package installation triggers post-install configuration scripts

Some Debian/Ubuntu packages automatically run dpkg-reconfigure during installation to:
• Set up initial configuration
• Ask interactive questions (even when -y is specified)
• The error appears because stdin isn't available in non-interactive sessions

Option 1: Use DEBIAN_FRONTEND
The most reliable approach is to set the frontend to noninteractive:

export DEBIAN_FRONTEND=noninteractive
sudo apt-get -y install php5-xsl graphviz php-pear unison

Option 2: Redirect stdin
For stubborn cases where packages still try to read stdin:

sudo apt-get -y install php5-xsl graphviz php-pear unison < /dev/null

Option 3: Full provisioning example
Here's how I handle this in my Vagrantfiles:

config.vm.provision "shell", inline: <<-SHELL
    export DEBIAN_FRONTEND=noninteractive
    apt-get update
    apt-get -y install php5-xsl graphviz php-pear unison
SHELL

Certain packages are more prone to this:
php-pear often tries to configure PECL settings
unison may attempt SSL certificate setup
• MySQL/MariaDB installations are classic offenders

For these, consider adding:

sudo apt-get -o Dpkg::Options::="--force-confdef" \
    -o Dpkg::Options::="--force-confold" \
    -y install problematic-package

For extreme cases where packages absolutely require input:

sudo apt-get -y install expect
expect << EOF
spawn apt-get install problem-package
expect "Do you want to continue?" {send "y\r"}
expect eof
EOF

Remember that suppressing these messages entirely isn't recommended - they might indicate actual configuration issues that should be addressed properly in your provisioning logic.


When automating Ubuntu VM provisioning through Vagrant, you might encounter this warning during package installation:

dpkg-reconfigure: unable to re-open stdin: No file or directory

This typically occurs when running commands like:

sudo apt-get -y install php5-xsl graphviz php-pear unison

The error appears because some packages attempt to run dpkg-reconfigure during installation, which expects an interactive terminal session. In automated environments like Vagrant provisioning:

  • The stdin file descriptor isn't available in non-interactive shells
  • Vagrant provisioning scripts run without a proper TTY
  • Package post-install scripts try to prompt for configuration

Here are several approaches to handle this issue:

# Solution 1: Set DEBIAN_FRONTEND environment variable
export DEBIAN_FRONTEND=noninteractive
sudo apt-get -y install php5-xsl graphviz php-pear unison

# Solution 2: Use -qq flag for quieter output
sudo apt-get -qq -y install php5-xsl graphviz php-pear unison > /dev/null 2>&1

# Solution 3: Redirect stdin from /dev/null
sudo apt-get -y install php5-xsl graphviz php-pear unison < /dev/null

For comprehensive handling in Vagrant provisioning:

config.vm.provision "shell", inline: <<-SHELL
  export DEBIAN_FRONTEND=noninteractive
  apt-get update
  apt-get -y -o Dpkg::Options::="--force-confdef" \
             -o Dpkg::Options::="--force-confold" \
             install php5-xsl graphviz php-pear unison
SHELL

For packages that absolutely require configuration:

# Pre-seed configuration for problematic packages
echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2" | debconf-set-selections
echo "phpmyadmin phpmyadmin/dbconfig-install boolean false" | debconf-set-selections
sudo apt-get -y install phpmyadmin

To identify which package is causing the reconfigure attempt:

# Check package post-install scripts
apt-get download PACKAGE_NAME
dpkg -e PACKAGE_NAME*.deb
grep -r "dpkg-reconfigure" DEBIAN/