0

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.

Leopd
  • 1,757
  • 4
  • 24
  • 30
  • 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 03 '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 03 '13 at 22:35

1 Answers1

5

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.

jtimberman
  • 7,587
  • 2
  • 34
  • 42
Tim Potter
  • 1,764
  • 15
  • 15