How to lazily evaluate an arbitrary variable with Chef
I haven't tested this particular code but I have done something similar in cookbooks and used a lambda to delay evaluation as follows:
home = lambda {node['etc']['passwd'][node['nodejs']['user']]['dir']}
execute "npm install" do
command "npm install #{prefix}#{app} --prefix #{home.call}"
end
Removing packages in Chef, from a generated list
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)
Related Topics
Ruby Get Time in Given Timezone
How to Get a List of Files That Have Been 'Required' in Ruby
Using Yield Inside Define_Method in Ruby
Why Do I Get "No Implicit Conversion of String into Integer (Typeerror)"
Concurrent Requests with Mri Ruby
Singleton Method VS. Class Method
Installing Ruby 2.3 on Wsl (Windows Subsystem for Linux)
Is Alias_Method_Chain Synonymous with Alias_Method
How to Install 'Cocoapods' Gem from Rubygems.Org (Bad Response Backend Read Error)
Select Mailbox "Sent Mail" or "All Mail" in Ruby Net::Imap
Rails/Rspec: How to Test #Initialize Method
<Rubygems> How to Change Gem Environment Settings
Understanding Ruby Symbol as Method Call
Strong Parameters Require Multiple