Running `apt-get upgrade` with Chef Solo

I'm using Chef Solo to provision a Vagrant VM based on Opscode's "Bento" box for Ubuntu 12.04. When it's done provisioning and I SSH in for the first time, the MOTD tells me there are packages and security updates. I then run sudo apt-get upgrade manually, which removes the message on subsequent logins. Is there a way to automate this step with Chef? The "apt" cookbook doesn't seem to handle this. All my Google searches find things only about apt-get update but not apt-get upgrade. I could just execute the apt-get command in my Chef recipe, but during the upgrade process, there is a pseudo-GUI on a pink screen where I have to select drives for installation (I think this is called GRUB, I'm new to Ubuntu) and I'm not sure how this part can be automated with Chef.


Solution 1:

I just encountered this exact issue myself with chef+vagrant and found the following worked for me:

sudo dpkg-reconfigure -plow grub-pc

This allows you to reconfigure grub-pc and select the device (if any) you want grub installed on. Setting a device as default here should allow an upgrade that includes grub to not prompt for a device selection. At this point you could create a new vagrant box and use that as your default.

or

To run an apt-get upgrade/dist-upgrade without being prompted you could use:

sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade
  • DEBIAN_FRONTEND=noninteractive uses the default answer to any prompt.
  • Dpkg::Options::="--force-confdef" ensures dpkg only overwrites config files you haven't modified
  • Dpkg::Options::="--force-confold" ensures the current config file is not overwritten. New config files are created with .dpkg-dist suffix.

Solution 2:

Adding "-y" will get past the prompts.

sudo apt-get upgrade -y

You should do this before the chef run, because chef may have cached the package versions in the apt database.