4

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.

3 Answers 3

5

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.
2
  • That command took me through a similar series of pink GRUB screens, including the same device selection I encounter when running apt-get upgrade. :|
    – Jimmy
    Feb 27, 2013 at 1:45
  • Well as I explained in my answer that is what it should do. It allows you to run an apt-get upgrade from that point on without a prompt. You could bundle it up and create a new vagrant base box at this point. Modifying my answer to give you a better alternative.
    – dok
    Feb 27, 2013 at 10:45
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.

2
  • Vagrant runs Chef Solo automatically when building the VM, so I'm not sure how I would run the upgrade "before" the Chef run. I tried just running the command with -y inside my main recipe, and it seemed to be processing fine, but then (presumably when it got to the GRUB part), it spat out a bunch of random characters to my shell and killed the whole Vagrant process.
    – Jimmy
    Feb 17, 2013 at 5:40
  • Using the -y parameter does not help with the GRUB interface.
    – Marius
    Jan 28, 2015 at 13:02
0

According to jtimberman himself, you should not run apt-get upgrade automatically.

The opscode recommended way to upgrade is on a package by package basis using the package resource.

package "php5-curl" do
  action :upgrade
end

For more details, read Don't run apt-get upgrade automatically in Chef

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .