So pardon the indenting:
ruby_block "apply-config" do
block do
::Dir["/srv/#{new_resource.artifactid}-#{new_resource.version}/templates/**/*"].each do |file|end
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}"
directory "/srv/#{new_resource.artifactid}-#{new_resource.version}/#{dirstocreate}" do
recursive true
action :create
not_if "test -d /srv/#{new_resource.artifactid}-#{new_resource.version}/#{dirstocreate}"
end
end
template "/srv/#{new_resource.artifactid}-#{new_resource.version}/#{newfilename[1]}" do
local true
source "#{file}"
end
end
end
action :nothing
end.run_action(:run)
??On Fri, Dec 21, 2012 at 6:40 PM, Maven User < " target="_blank"> > wrote:Could I have put that inside a ruby block or would I lose the resources inside there?The full block of code I have has ruby wrapping resources:The tickets also confused me more >.<I'm also not clear about the "action :nothing" and the run_action bits you're mentioning above - any usecase links?I'm trying to solve a scenario where we have a dozen recipes that they ALL do the same 70 lines of code. So I'm trying to refactor that away in to a lwrp.WOW - dood - thank you!I'm a bit overwhelmed by the reply and trying to grock it - so bear with me....
:Dir["/srv/#{new_resource.artifactid}-#{new_resource.version}/templates/**/*"].each do |file|if (::File.file?(file))
puts "here is the 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}"
directory "/srv/#{new_resource.artifactid}-#{new_resource.version}/#{dirstocreate}" do
recursive true
action :create
not_if "test -d /srv/#{new_resource.artifactid}-#{new_resource.version}/#{dirstocreate}"
end
end
template "/srv/#{new_resource.artifactid}-#{new_resource.version}/#{newfilename[1]}" do
local true
source "#{file}"
end
end
end
On Fri, Dec 21, 2012 at 6:19 PM, Daniel DeLeo < " target="_blank"> > wrote:
On Friday, December 21, 2012 at 2:54 PM, Maven User wrote:
Am I missing something?It also seems to run some of the steps out of order (right above this block in the provider is an unzip step which now is run AFTER the Dir bit...).Hmmm - some new weirdness...The first time a recipe is run that is using this provider, that evaluates to nothing, so the subsequent lines are skipped.
I have a block of ruby code like this in the provider:
Dir["/srv/#{new_resource.artifactid}-#{new_resource.version}/templates/**/*"].each do |file|
puts "here is the file #{file}"
....
Short: This is basically the LWRP version of the compile/converge phase issue. Use action :nothing and run_action to make resources execute immediately.Long:LWRPs currently handle nested resources by inserting them in the top-level resource collection *after* the LWRP's position in the resource collection. For a recipe like this:resource_onelwrp_resource -> sub_resource_one, sub_resource_tworesource_three…after lwrp_resource is converged, your resource collection looks like:resource_one #already executedlwrp_resource #already executedsub_resource_onesub_resource_tworesource_threeThis implementation was chosen so that the "sub resources" within an LWRP could notify resources outside of the LWRP. The downside is that the LWRP resource itself cannot properly determine if it was updated or not. See:In either of the "insert after" or "inline recipe" implementations, you'll still have the general compile/converge pattern, which means that raw ruby code that's not wrapped in a ruby block will execute *before* resources, unless you force the issue with #run_action.Another option for implementing LWRPs would be to scrap the compile/converge distinction altogether, but then notifications are pretty much impossible, which makes anything that wants to trigger an execute resource based on something else being updated (like a config file) much more difficult to write.--Daniel DeLeo
Archive powered by MHonArc 2.6.16.