I was wondering if it was possible to use a chef resource such as ‘file’ or
’cookbook_file’ in a custom library. I have tried the following and none of
them have been successful:
class Chef
class Recipe
class myhelper
file “…” do
end
class Chef
class Resource
class myhelper
file “…” do
end
class Chef
class Resource
class myhelper < ::Chef::Resource
Library code is just 100% plain ruby code, so you can't use the recipe dsl unless you do special stuff to set that up. If you are trying to write class based resources using the lwp dsl, check out Poise and some of the cookbooks using it.
I was wondering if it was possible to use a chef resource such as
'file' or
'cookbook_file' in a custom library. I have tried the following and
none of
them have been successful:
class Chef
class Recipe
class myhelper
file "..." do
end
class Chef
class Resource
class myhelper
file "..." do
end
class Chef
class Resource
class myhelper < ::Chef::Resource
Library code is just 100% plain ruby code, so you can't use the recipe dsl
unless you do special stuff to set that up. If you are trying to write
class based resources using the lwp dsl, check out Poise and some of the
cookbooks using it.
I was wondering if it was possible to use a chef resource such as 'file'
or 'cookbook_file' in a custom library. I have tried the following and none
of them have been successful:
class Chef
class Recipe
class myhelper
file "..." do
end
class Chef
class Resource
class myhelper
file "..." do
end
class Chef
class Resource
class myhelper < ::Chef::Resource
take a look at the chef-apply code[1],
all resources in chef requires a run context, you can learn how to build
run context from that code, after that either you can take the recipe route
(i.e. instance_eval ruby code having file, cookbook_file etc, using
Chef::Recipe) or the explicit Chef::File.new('/path',
rc).run_action(:create) route
I was wondering if it was possible to use a chef resource such as 'file'
or 'cookbook_file' in a custom library. I have tried the following and none
of them have been successful:
class Chef
class Recipe
class myhelper
file "..." do
end
class Chef
class Resource
class myhelper
file "..." do
end
class Chef
class Resource
class myhelper < ::Chef::Resource