Skip to content

Instantly share code, notes, and snippets.

@rnp
Created May 25, 2010 21:54
Show Gist options
  • Save rnp/413748 to your computer and use it in GitHub Desktop.
Save rnp/413748 to your computer and use it in GitHub Desktop.
resource def file (in recipe test for time being)
#based on deploy resource; didnt use lwrp because had to pass in a block
def initialize(name, collection=nil, node=nil)
super(name, collection, node)
@resource_name = :test_nested
@action = "create"
@allowed_actions.push(:create)
end
def block(&block)
if block_given? and block
@block = block
else
@block
end
end
===
provider file
def load_current_resource
true
end
def action_create
@collection = Chef::ResourceCollection.new
recipe_eval(&@new_resource.block)
end
#to handle case where include_recipe directly in nest block
def include_recipe(recipe)
nested_recipe = Chef::Recipe.new@new_resource(@new_resource.cookbook_name,@new_resource.recipe_name,@new_resource.node,@collection, nil, nil)
nested_recipe.include_recipe(recipe)
end
====
sample "setting recipe"
ruby_block "x" do
block do
node.set[:test] = "in_ruby_block"
#not sure whether a node.save is needed
end
end
===
sample calling recipe
test_nested "foo" do
block do
Chef::Log.info("in nested: node test = #{node[:test]}")
execute "touch /tmp/#{node[:test]}.txt" do
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment