Resource in a ruby_block?

I’m looking to do something like this…

ruby_block “do something doing convergence” do
block do
check_value=result_from_database_at_convergence_run_time

	if check_value==0 then
		execute "run my sql script" do
			cwd "path_to_script"
			user "root"
			command "./execute_sql_file.rb"
		end
	end
end
only_if do primary_idempotent_condition==true end

end

is this possible? am I missing something?

Jeremy Winters
212-202-0449 x1023
jeremy.winters@full360.com

Why the nesting? Can you not make the inner operation idempotent based
on the primary condition? You can pass a block to the idempotence
statements. I do this in my user cookbook:

On Thu, Mar 17, 2011 at 11:31 PM, Jeremy Winters
jeremy.winters@full360.com wrote:

I'm looking to do something like this...

ruby_block "do something doing convergence" do
block do
check_value=result_from_database_at_convergence_run_time

           if check_value==0 then
                   execute "run my sql script" do
                           cwd "path_to_script"
                           user "root"
                           command "./execute_sql_file.rb"
                   end
           end
   end
   only_if do primary_idempotent_condition==true end

end

is this possible? am I missing something?

Jeremy Winters
212-202-0449 x1023
jeremy.winters@full360.com

the problem is that the idempotent condition determines whether or not to run the ruby_block... but the decision to run the execute resource can only be determined during convergence... and not during the compilation phase... as the data in the database is changed in an earlier step during convergence.

looking at your recipe... am I correct that everything outside of the execute is evaluated during the compilation phase?

Jeremy Winters
212-202-0449 x1023
jeremy.winters@full360.com

On Mar 17, 2011, at 11:35 PM, John E. Vincent (lusis) wrote:

Why the nesting? Can you not make the inner operation idempotent based
on the primary condition? You can pass a block to the idempotence
statements. I do this in my user cookbook:

user-cookbook-mysql-perms.rb · GitHub

On Thu, Mar 17, 2011 at 11:31 PM, Jeremy Winters
jeremy.winters@full360.com wrote:

I'm looking to do something like this...

ruby_block "do something doing convergence" do
block do
check_value=result_from_database_at_convergence_run_time

           if check_value==0 then
                   execute "run my sql script" do
                           cwd "path_to_script"
                           user "root"
                           command "./execute_sql_file.rb"
                   end
           end
   end
   only_if do primary_idempotent_condition==true end

end

is this possible? am I missing something?

Jeremy Winters
212-202-0449 x1023
jeremy.winters@full360.com

Ohai!

On Thu, Mar 17, 2011 at 9:47 PM, Jeremy Winters
jeremy.winters@full360.com wrote:

the problem is that the idempotent condition determines whether or not to run the ruby_block... but the decision to run the execute resource can only be determined during convergence... and not during the compilation phase... as the data in the database is changed in an earlier step during convergence.

If whatever updating the data in the database is a resource, you can
notify the execute.

Supposing it is an execute resource that runs some command that
updates the database:

execute "thing that updates database" do
  notifies :run, "execute[run my sql script"
end

execute "run my sql script" do
  cwd "path_to_script"
  user "root"
  command "./execute_sql_file.rb"
  action :nothing
end

--
Opscode, Inc
Joshua Timberman, Technical Evangelist
IRC, Skype, Twitter, Github: jtimberman