How do I uninstall DMG's with puppet?

884 views Asked by At

So I have a local DMG that I'm installing with puppet (VirtualBox-4.2.18-88780-OSX.dmg), and I run it with

sudo puppet resource package virtualbox ensure=present provider=pkgdmg source=puppet:///virtualbox/VirtualBox-4.2.18-88780-OSX.dmg,

and everything works fine. But when I try to remove it with sudo puppet resource package virtualbox ensure=absent, I get an error

Error: Could not set 'absent' on ensure: undefined method 'uninstall' for #<Puppet::Type::Package::ProviderPkgdmg:0x107cb8218>

I have a vague idea of why this is happening, it doesn't look like puppet is recognizing the virtualbox uninstall tool. How do I fix this?

2

There are 2 answers

1
iamauser On

I would use an exec resource to do the uninstall rather than the package resource.

exec { "uninstall_mypkg" :
  command => "uninstall mypkg",
  onlyif => "check if the package is installed",
  path => "/path/to/command/",
}
0
Ryan Skoblenick On

millmouse is correct OS X packages can't be uninstalled, at least by this method. Puppet doesn't support 'absent' on appdmg or apppkg providers.

You can however trick Puppet to reinstall a package by removing the 'cookie' like file it creates to track the package was installed. Puppet creates a file in /var/db with a pattern like .puppet_<provider>_installed_<package_name>-<version> on OS X; for example you'll have a file like /var/db/.puppet_pkgdmg_installed_VirtualBox-4.2.18-88780

You could do something like the following, but it won't actually uninstall the app only trick Puppet into allowing it to be installed again:

exec {'rm -f .puppet_pkgdmg_installed_VirtualBox-4.2.18-88780':
  cwd => /var/db/',
  user => 'root',
  onlyif => 'test -f /var/db/.puppet_pkgdmg_installed_VirtualBox-4.2.18-88780',
}

or

file {'/var/db/.puppet_pkgdmg_installed_VirtualBox-4.2.18-88780':
  ensure => 'absent',
  force => true,
}

Otherwise the version number or name of the package needs to change in order to install again.