This is working (for now).Gotcha - your rewrite of my example is a bit wrong - I'm using any files found in a given directory as templates and recreating the entire folder structure up one directory expanding the templates as I go.I'm also using the ruby_block syntax too:
The trick was to get the directory provider working within the ruby block.
I'm _not_ sure this is the right thing to do or not (but it cleaned up my code slightly), but I created two defs - one for directories and one for the templates that are needed.
def mkdir (dirname)
directory "#{dirname}" do
recursive true
action :create
end
end
def mktemplate (templatename, sourcefile)
template "#{templatename}" do
local true
source "#{sourcefile}"
end
endmkdir("/srv/#{new_resource.artifactid}-#{new_resource.version}/#{dirstocreate}")
ruby_block "apply-config" do
block do
::Dir["/srv/#{new_resource.artifactid}-#{new_resource.version}/templates/**/*"].each do |file|
puts "here is the file #{file}"
if (::File.file?(file))
puts "#{filename} is a file -> #{file}"
filename = ::File.basename(file)
newfilename = ::File.absolute_path(file).split("templates/")
puts "here is the new file name #{newfilename[1]}"
if (newfilename[1].rindex('/') != nil && newfilename[1].rindex('/') > 1)
puts "there are directories we need to create"
dirstocreate = newfilename[1][0, newfilename[1].rindex('/')]
puts "We need to make #{dirstocreate}"
end
mktemplate("/srv/#{new_resource.artifactid}-#{new_resource.version}/#{newfilename[1]}", "#{file}")
end
end
end
end
On Fri, Dec 21, 2012 at 8:29 PM, Daniel DeLeo < " target="_blank"> > wrote:
On Friday, December 21, 2012 at 4:15 PM, Maven User wrote:
actually - I'm a BIT further now (maybe).
So removing the action and end.run_action items, I can see now it's executing the ruby code when it should.
BUT - now it doesn't understand what a "directory" or a "template" is - how do I import these things?You went a bit in the wrong direction. I'd recommend either:1) use resources like normal, and put raw ruby code into ruby blocks:action :something dodirectory "path" do#stuffendruby_block "arbitrary_code" doblock do# some codeendendfile "path/file" do#stuffendendOR2) Use action :nothing plus run_action, but *no* ruby blocksaction :something dodirectory "path" do#stuffaction :nothingrun_action(:create) # this works if it's very lastend # or you can put `.run_action()` here, it'll be the same result# random ruby code, NO ruby_block resourcer = file "path/file" do#stuffaction :nothingendr.run_action(:create) # this is the other way to use run_action(): assign resource to a variableendThis example is a little complicated, but you should be able to see the general pattern:--Daniel DeLeo
Archive powered by MHonArc 2.6.16.