A cow-orker came to me with a puppet issue today. He was trying to remove a package from a fleet of RedHat servers, using ensure => absent in the package resource, but it was failing:

Error: Execution of '/bin/rpm -e firefox' returned 1: error: "firefox" specifies multiple packages:
  firefox-78.9.0-1.el7_9.x86_64
  firefox-78.9.0-1.el7_9.i686
Error: /Stage[main]/Profile::Base::Firefox/Package[firefox]/ensure: change from '78.9.0-1.el7_9' to 'absent' failed: Execution of '/bin/rpm -e firefox' returned 1: error: "firefox" specifies multiple packages:
  firefox-78.9.0-1.el7_9.x86_64
  firefox-78.9.0-1.el7_9.i686

A quick search showed that rpm has an --allmatches option. From rpm(8):

--allmatches
       Remove all versions of the package which match PACKAGE_NAME.
       Normally an error is issued if PACKAGE_NAME matches multiple packages.

Since the rpm provider has the uninstall_options feature, I suggested he add uninstall_options => [ '--allmatches' ] to the package resource. Unfortunately this failed, too. Running a debug showed that it was still just executing rpm -e and ignoring the additional options.

Looking further, I see that the yum provider is actually the default on RedHat, and that it does not support the uninstall_options feature.

yum

Support via yum.

Using this provider’s uninstallable feature will not remove dependent packages. To remove dependent packages with this provider use the purgeable feature, but note this feature is destructive and should be used with the utmost care.

This provider supports the install_options attribute, which allows command-line flags to be passed to yum. These options should be specified as an array where each element is either a string or a hash.

  • Required binaries: yum, rpm
  • Default for: osfamily == redhat
  • Supported features: install_options, installable, purgeable, uninstallable, upgradeable, versionable, virtual_packages

Our second try was a success:

package { 'firefox':
  ensure            => absent,
  provider          => 'rpm',
  uninstall_options => [ '--allmatches', '--nodeps' ],
}