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
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:
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
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?
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:
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
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