Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 4 down vote accepted

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.
share|improve this answer
    
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 Cuadra Feb 27 '13 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 '13 at 10:45

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.

share|improve this answer
    
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 Cuadra Feb 17 '13 at 5:40

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.