Skip to content

Instantly share code, notes, and snippets.

@imlucas
Created December 5, 2013 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imlucas/7812280 to your computer and use it in GitHub Desktop.
Save imlucas/7812280 to your computer and use it in GitHub Desktop.
How to use converge_by in Chef LWRP's. This is from an app cookbook I forked from the main opscode application cookbook but stripped way down.
action :deploy do
before_compile
before_deploy
run_deploy
new_resource.updated_by_last_action(true)
end
protected
def install_packages
converge_by("install app packages (#{new_resource.packages.length})") do
new_resource.packages.each do |pkg|
Chef::Log.warn "Install #{pkg}"
package pkg do
action :install
end
end
end
end
def before_compile
install_packages
new_resource.app_provider self
if new_resource.before_compile
ruby_block "#{new_resource.name} before_compile" do
block do
callback(:before_compile, new_resource.before_deploy)
end
end
end
converge_by("run subresource before_compile hooks (#{new_resource.sub_resources.length})") do
new_resource.sub_resources.each do |resource|
resource.app_provider self
resource.run_action :before_compile
end
end
end
def before_deploy
verify_directories_exist
if new_resource.before_deploy
ruby_block "#{new_resource.name} before_deploy" do
block do
callback(:before_deploy, new_resource.before_deploy)
end
end
end
end
@timurb
Copy link

timurb commented Jul 30, 2014

Are you sure you need converge_by blocks here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment