Created
May 25, 2010 21:54
-
-
Save rnp/413748 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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