Callus Tacticus
Callus Tacticus

Reputation: 13

Removing packages in Chef, from a generated list

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?

Upvotes: 1

Views: 229

Answers (1)

Roland
Roland

Reputation: 1426

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)

Upvotes: 1

Related Questions