I have a recipe with multiple calls to a given resource, let's say directory
. The calls to directory
, for the most part, have very similar parameters (i.e. same owner, same action, etc.) - i.e. a lot of duplication. However, there is a particular parameter that changes frequently, namely the mode.
My goal is to reduce the duplication in my recipes and create something of a convenience method.
I'm leaning towards creating a library with a method like this:
def apply_directory_rule(path, mode_num)
directory path do
owner "something"
group "something_else"
mode mode_num
action :create
end
end
Then, in the recipe, each time I wanted to create a directory for the applications, I would simply call the following:
applications.each do |application|
apply_directory_rule "#{application}/shared", 0755
end
I have not been able to test this yet, but I guess my main question is whether or not Resources, in this case directory
are available like this in libraries? Secondarily, I'm not convinced this is the best pattern - any suggestions to reduce this duplication in my recipes is appreciated!