'Chef: Calling a custom resource based on variable name

We have a number of RPMs that we list in a role that can be deployed, as desired, via a loop. for installation this works well.

However, removal of these RPMs is a little more involved - including tidying up of directories that are longer required, backing up logs, etc.

In Chef is it possible to do something like:

node['rpm'].each do |rpm_name|
  remove_res = "remove_#{rpm_name}"

  remove_res 'removing' do
    log "Removing #{rpm_name}"
    not_if { node['rpm']['install'] }
  end
end

I want to avoid using mutiple if..elsif statements or case..when if I can. Both these options mean repeating code.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source