1
votes

I am trying to generate a list of packages during the chef run and remove them.

I've tried to use a ruby block to set a run_state variable. The variable ends up being empty. I also tried adding lazy evaluation in package based on this question but it resulted in compile errors. I have also looked into placing the list in a file but the docs say support for using file names for package is not available.

Is there a reasonable way to remove a list of packages from a converge time variable?

1

1 Answers

1
votes

How about this:

ruby_block "somehow get the list of packages to remove" do
  block do
    node.run_state['remove_packages'] = %w( foo bar baz )
  end
end

package "remove the list of packages" do
  package_name lazy { node.run_state['remove_packages'] }
  action :remove
  only_if { node.run_state['remove_packages'] }
end

(tested with chef-apply 13.5.3)