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

An older version of a cookbook installed a package that I no longer want on my systems. My understanding is that chef doesn't have a straightforward way to explicitly remove a package, so I resorted to the blunt hammer of execute:

execute "Remove nasty perl gearman-server" do
    command "apt-get -y remove gearman-server"
    ignore_failure true
end

But this fails, I'm guessing because chef itself has the lock on dpkg?

STDERR: E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

How can I programmatically ensure that this package is no longer on my machines? If it's not clear, I'm totally happy with an ubuntu-only solution.

share|improve this question
    
That error indicates some other package tool was already running. Were doing something in another window/terminal? I don't know chef, but I find it difficult to believe that it create that lock. –  Zoredache Jan 3 '13 at 22:10
    
Agreed. The lock must have been taken by another dpkg or apt process, possibly another chef-client also. –  Tim Potter Jan 3 '13 at 22:35

1 Answer 1

up vote 5 down vote accepted

The Chef package resource allows removal or purging of packages in a distro independent manner:

package "gearman-server" do
  action :remove
end

This code will remove the package if it is installed, or do nothing if the package is not.

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.