1

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 Answers1

1

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)

coderanger
  • 52,400
  • 4
  • 52
  • 75
Roland
  • 1,426
  • 9
  • 9
  • 1
    I fixed the answer to use run_state instead of a node attribute. You should almost never write to node attributes for scratch space like this. – coderanger Nov 08 '17 at 19:57
  • True, if you don't want to store the value on the chef-server. – Roland Nov 08 '17 at 21:06