# NoMethodError for LWRP within a ruby\_block?

**URL:** <https://discourse.chef.io/t/nomethoderror-for-lwrp-within-a-ruby-block/4848>\
**Category:** Chef Infra (archive)\
**Created:** [December 4, 2013, 7:06pm UTC](https://discourse.chef.io/t/nomethoderror-for-lwrp-within-a-ruby-block/4848 "2013-12-04T19:06:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kallen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallen/32/1049_2.png) [@Kallen](https://discourse.chef.io/u/Kallen)\
**Post date:** [December 4, 2013, 7:06pm UTC](https://discourse.chef.io/t/nomethoderror-for-lwrp-within-a-ruby-block/4848/1 "2013-12-04T19:06:58Z")

</div>

Hiya,

How do I make an LWRP that I created available in a recipe within a ruby\_block?  
It’s not working for me.

[2013-12-04T00:13:14+00:00] DEBUG: Re-raising exception: NoMethodError - ruby\_block[do stuff] (cloner::grants line 30) had an error: NoMethodError: undefined method `cloner_db_svc_mysqlacl' for Chef::Resource::RubyBlock /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/resource.rb:294:in`method\_missing’  
/var/cache/chef/cookbooks/cloner/recipes/grants.rb:67:in `block (2 levels) in from_file' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider/ruby_block.rb:33:in`call’  
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider/ruby\_block.rb:33:in `block in action_run' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/mixin/why_run.rb:52:in`call’  
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/mixin/why\_run.rb:52:in `add_action' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider.rb:149:in`converge\_by’  
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider/ruby\_block.rb:32:in `action_run' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider.rb:114:in`run\_action’  
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/resource.rb:625:in `run\_action’  
…

Afaict, the recipe code needs to execute during the convergence phase of the  
chef-client run. In my case, the code needs to (1) first start mysql, (2) wait  
for mysql to complete its startup (wait for innodb recovery to complete) and (3)  
then query a value from a table. (4) And then do another action depending on the  
value returned.

I tried doing the above outside a ruby\_block my first time through, then  
realized #3 was executing before #2 had completed. IOW #3 was executing at the  
compile phase. So now I’m trying to put all of this into a ruby\_block, but the  
call to my LWRP is failing. (Is using a ruby\_block for this the right answer?)

The LWRP lives in ‘cloner-db-svc’ cookbook. The cookbook::recipe that calls it  
is ‘cloner::grants’. The cloner cookbook depends on cloner-db-svc. When the code  
runs outside of a ruby\_block, the recipe finds the LWRP method just fine, but  
the behavior I need doesn’t occur.

::Chef::Recipe.send(:include, ::Cloner::Chef::DbSvc::Helper)

ruby\_block “do stuff” do  
block do  
quux\_ip = search(:node, ‘roles:quux’).map {|server| server[‘ipaddress’] }.join(",")  
cli\_password = ::Cloner::Chef::DbSvc::Helper.fetchsecret( “secrets”, “#{node[‘cloner’][‘environment’]}”, “rootpass” )  
current\_ip = %x( mysql --skip-column-names -hlocalhost -uroot -p#{cli\_password} -e “SELECT Host FROM mysql.user WHERE User=‘cloner\_admin’” )

```
if current_ip.empty?
  Chef::Log.debug("HIGGS-BOSON: current_ip is empty, applying grants.")
  cloner_admin_pass = ::Cloner::Chef::DbSvc::Helper.fetchsecret( "secrets", "#{node['cloner']['environment']}", "cloner_admin_pass" )
  cloner_proc_pass = ::Cloner::Chef::DbSvc::Helper.fetchsecret( "secrets", "#{node['cloner']['environment']}", "cloner_proc_pass" )

  cloner_db_svc_mysqlacl "mysqlgrants" do
    action :create_acl
    ipv4_address quux_ip
    cli_password cli_password
    cloner_admin_pass cloner_admin_pass
    cloner_proc_pass cloner_proc_pass
  end
  current_ip = %x( mysql --skip-column-names -hlocalhost -uroot -p#{cli_password} -e \"SELECT Host FROM mysql.user WHERE User='cloner_admin'\" )
  Chef::Log.debug("HIGGS-BOSON: After applying mysqlgrants, quux_ip #{quux_ip}; current_ip #{current_ip}")

else # snipped for brevity
end

```

end  
action :create  
end

Thanks!  
kallen

---

<div class="post-metadata">

**Author:** ![Brian\_Fletcher](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/brian_fletcher/32/414_2.png) [@Brian\_Fletcher](https://discourse.chef.io/u/Brian_Fletcher)\
**Post date:** [December 4, 2013, 10:39pm UTC](https://discourse.chef.io/t/nomethoderror-for-lwrp-within-a-ruby-block/4848/2 "2013-12-04T22:39:23Z")

</div>

Hi Callen,

When inside a ruby\_block the chef DSL doesn't work. You need to use pure  
ruby. Here is an example of how you can execute a resource from a  
ruby\_block. The cookbook is called 'test' and the lwrp is called 'mine'.

ruby\_block 'dd' do  
block do  
mine = Chef::Resource::TestMine.new('bb', run\_context)  
mine.run\_action(:create)  
end  
action :create  
end

You will need something like the following. The lwrp name is turned into  
camel case.

mysqlacl = Chef::Resource::ClonerDbSvcMysqlacl("mysqlgrants", run\_context)  
mysqlacl.ipv4\_address(quux\_ip)  
Š

mysqlacl.run\_action(:create\_acl)

Regarding whether its the right thing to do, I try to avoid them if  
possible. This is because it is difficult to make assertions about the  
actions executed within a ruby\_block using chefspec (unit testing for  
chef).

Thanks,

Brian

On 04/12/2013 19:06, "[kallen@groknaut.net](mailto:kallen@groknaut.net)" [kallen@groknaut.net](mailto:kallen@groknaut.net) wrote:

> Hiya,
> 
> How do I make an LWRP that I created available in a recipe within a  
> ruby\_block?  
> It's not working for me.
> 
> [2013-12-04T00:13:14+00:00] DEBUG: Re-raising exception: NoMethodError -  
> ruby\_block[do stuff] (cloner::grants line 30) had an error:  
> NoMethodError: undefined method `cloner_db_svc_mysqlacl' for Chef::Resource::RubyBlock /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/resource. rb:294:in `method\_missing'  
> /var/cache/chef/cookbooks/cloner/recipes/grants.rb:67:in `block (2  
> levels) in from\_file'
> 
> /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider/  
> ruby\_block.rb:33:in `call'
> 
> /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider/  
> ruby\_block.rb:33:in `block in action\_run'
> 
> /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/mixin/why  
> \_run.rb:52:in `call'
> 
> /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/mixin/why  
> \_run.rb:52:in `add\_action'
> 
> /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider.  
> rb:149:in `converge\_by'
> 
> /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider/  
> ruby\_block.rb:32:in `action\_run'
> 
> /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider.  
> rb:114:in `run\_action'
> 
> /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/resource.  
> rb:625:in `run\_action'  
> ...
> 
> Afaict, the recipe code needs to execute during the convergence phase of  
> the  
> chef-client run. In my case, the code needs to (1) first start mysql, (2)  
> wait  
> for mysql to complete its startup (wait for innodb recovery to complete)  
> and (3)  
> then query a value from a table. (4) And then do another action depending  
> on the  
> value returned.
> 
> I tried doing the above outside a ruby\_block my first time through, then  
> realized #3 was executing before #2 had completed. IOW #3 was executing  
> at the  
> compile phase. So now I'm trying to put all of this into a ruby\_block,  
> but the  
> call to my LWRP is failing. (Is using a ruby\_block for this the right  
> answer?)
> 
> The LWRP lives in 'cloner-db-svc' cookbook. The cookbook::recipe that  
> calls it  
> is 'cloner::grants'. The cloner cookbook depends on cloner-db-svc. When  
> the code  
> runs outside of a ruby\_block, the recipe finds the LWRP method just fine,  
> but  
> the behavior I need doesn't occur.
> 
> ::Chef::Recipe.send(:include, ::Cloner::Chef::DbSvc::Helper)
> 
> ruby\_block "do stuff" do  
> block do  
> quux\_ip = search(:node, 'roles:quux').map {|server|  
> server['ipaddress'] }.join(",")  
> cli\_password = ::Cloner::Chef::DbSvc::Helper.fetchsecret( "secrets",  
> "#{node['cloner']['environment']}", "rootpass" )  
> current\_ip = %x( mysql --skip-column-names -hlocalhost -uroot  
> -p#{cli\_password} -e "SELECT Host FROM mysql.user WHERE  
> User='cloner\_admin'" )
> 
> if current\_ip.empty?  
> Chef::Log.debug("HIGGS-BOSON: current\_ip is empty, applying  
> grants.")  
> cloner\_admin\_pass = ::Cloner::Chef::DbSvc::Helper.fetchsecret(  
> "secrets", "#{node['cloner']['environment']}", "cloner\_admin\_pass" )  
> cloner\_proc\_pass = ::Cloner::Chef::DbSvc::Helper.fetchsecret(  
> "secrets", "#{node['cloner']['environment']}", "cloner\_proc\_pass" )
> 
> ```
> cloner_db_svc_mysqlacl "mysqlgrants" do
> action :create_acl
> ipv4_address quux_ip
> cli_password cli_password
> cloner_admin_pass cloner_admin_pass
> cloner_proc_pass cloner_proc_pass
> end
> current_ip = %x( mysql --skip-column-names -hlocalhost -uroot
> 
> ```
> 
> -p#{cli\_password} -e "SELECT Host FROM mysql.user WHERE  
> User='cloner\_admin'" )  
> Chef::Log.debug("HIGGS-BOSON: After applying mysqlgrants, quux\_ip  
> #{quux\_ip}; current\_ip #{current\_ip}")
> 
> else # snipped for brevity  
> end  
> end  
> action :create  
> end
> 
> Thanks!  
> kallen

---

<div class="post-metadata">

**Author:** ![Kallen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallen/32/1049_2.png) [@Kallen](https://discourse.chef.io/u/Kallen)\
**Post date:** [December 5, 2013, 7:17pm UTC](https://discourse.chef.io/t/nomethoderror-for-lwrp-within-a-ruby-block/4848/3 "2013-12-05T19:17:13Z")

</div>

Thanks for the response. I forgot chef DSL isn't available within a ruby\_block.  
Basically, I'm trying to get my recipe actions executing in the right order,  
using the chef tools as I understand them so far. I'll probably try run\_context  
today.

Given my cookbook, the run order I desire is:

1. Start mysql
2. Wait for innodb recovery to complete (i.e. wait for mysql to respond to queries).
3. Query a value from mysql
4. Take action on that value using my LWRP

But the run order that actually happened before I tried putting 3 and 4 into  
a ruby\_block was:

1. Query a value from mysql (got executed at compile phase)
2. Take action on that value using my LWRP (got executed at compile phase)
3. Start mysql (got executed at convergence phase)
4. Wait for innodb recovery to complete (i.e. wait for mysql to respond to queries). (got executed at convergence phase)

Items executing at compile phase rather than convergence phase is working  
against me, I feel. I'll keep trying.

thx,  
kallen

On Wed, 04 Dec 2013, Brian Fletcher wrote:

> Hi Callen,
> 
> When inside a ruby\_block the chef DSL doesn't work. You need to use pure  
> ruby. Here is an example of how you can execute a resource from a  
> ruby\_block. The cookbook is called 'test' and the lwrp is called 'mine'.
> 
> ruby\_block 'dd' do  
> block do  
> mine = Chef::Resource::TestMine.new('bb', run\_context)  
> mine.run\_action(:create)  
> end  
> action :create  
> end
> 
> You will need something like the following. The lwrp name is turned into  
> camel case.
> 
> mysqlacl = Chef::Resource::ClonerDbSvcMysqlacl("mysqlgrants", run\_context)  
> mysqlacl.ipv4\_address(quux\_ip)  
> ?
> 
> mysqlacl.run\_action(:create\_acl)
> 
> Regarding whether its the right thing to do, I try to avoid them if  
> possible. This is because it is difficult to make assertions about the  
> actions executed within a ruby\_block using chefspec (unit testing for  
> chef).
> 
> Thanks,
> 
> Brian
> 
> On 04/12/2013 19:06, "[kallen@groknaut.net](mailto:kallen@groknaut.net)" [kallen@groknaut.net](mailto:kallen@groknaut.net) wrote:
> 
> > Hiya,
> > 
> > How do I make an LWRP that I created available in a recipe within a  
> > ruby\_block?  
> > It's not working for me.
> > 
> > [2013-12-04T00:13:14+00:00] DEBUG: Re-raising exception: NoMethodError -  
> > ruby\_block[do stuff] (cloner::grants line 30) had an error:  
> > NoMethodError: undefined method `cloner_db_svc_mysqlacl' for Chef::Resource::RubyBlock /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/resource. rb:294:in `method\_missing'  
> > /var/cache/chef/cookbooks/cloner/recipes/grants.rb:67:in `block (2  
> > levels) in from\_file'
> > 
> > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider/  
> > ruby\_block.rb:33:in `call'
> > 
> > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider/  
> > ruby\_block.rb:33:in `block in action\_run'
> > 
> > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/mixin/why  
> > \_run.rb:52:in `call'
> > 
> > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/mixin/why  
> > \_run.rb:52:in `add\_action'
> > 
> > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider.  
> > rb:149:in `converge\_by'
> > 
> > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider/  
> > ruby\_block.rb:32:in `action\_run'
> > 
> > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider.  
> > rb:114:in `run\_action'
> > 
> > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/resource.  
> > rb:625:in `run\_action'  
> > ...
> > 
> > Afaict, the recipe code needs to execute during the convergence phase of  
> > the  
> > chef-client run. In my case, the code needs to (1) first start mysql, (2)  
> > wait  
> > for mysql to complete its startup (wait for innodb recovery to complete)  
> > and (3)  
> > then query a value from a table. (4) And then do another action depending  
> > on the  
> > value returned.
> > 
> > I tried doing the above outside a ruby\_block my first time through, then  
> > realized #3 was executing before #2 had completed. IOW #3 was executing  
> > at the  
> > compile phase. So now I'm trying to put all of this into a ruby\_block,  
> > but the  
> > call to my LWRP is failing. (Is using a ruby\_block for this the right  
> > answer?)
> > 
> > The LWRP lives in 'cloner-db-svc' cookbook. The cookbook::recipe that  
> > calls it  
> > is 'cloner::grants'. The cloner cookbook depends on cloner-db-svc. When  
> > the code  
> > runs outside of a ruby\_block, the recipe finds the LWRP method just fine,  
> > but  
> > the behavior I need doesn't occur.
> > 
> > ::Chef::Recipe.send(:include, ::Cloner::Chef::DbSvc::Helper)
> > 
> > ruby\_block "do stuff" do  
> > block do  
> > quux\_ip = search(:node, 'roles:quux').map {|server|  
> > server['ipaddress'] }.join(",")  
> > cli\_password = ::Cloner::Chef::DbSvc::Helper.fetchsecret( "secrets",  
> > "#{node['cloner']['environment']}", "rootpass" )  
> > current\_ip = %x( mysql --skip-column-names -hlocalhost -uroot  
> > -p#{cli\_password} -e "SELECT Host FROM mysql.user WHERE  
> > User='cloner\_admin'" )
> > 
> > if current\_ip.empty?  
> > Chef::Log.debug("HIGGS-BOSON: current\_ip is empty, applying  
> > grants.")  
> > cloner\_admin\_pass = ::Cloner::Chef::DbSvc::Helper.fetchsecret(  
> > "secrets", "#{node['cloner']['environment']}", "cloner\_admin\_pass" )  
> > cloner\_proc\_pass = ::Cloner::Chef::DbSvc::Helper.fetchsecret(  
> > "secrets", "#{node['cloner']['environment']}", "cloner\_proc\_pass" )
> > 
> > ```
> > cloner_db_svc_mysqlacl "mysqlgrants" do
> > action :create_acl
> > ipv4_address quux_ip
> > cli_password cli_password
> > cloner_admin_pass cloner_admin_pass
> > cloner_proc_pass cloner_proc_pass
> > end
> > current_ip = %x( mysql --skip-column-names -hlocalhost -uroot
> > 
> > ```
> > 
> > -p#{cli\_password} -e "SELECT Host FROM mysql.user WHERE  
> > User='cloner\_admin'" )  
> > Chef::Log.debug("HIGGS-BOSON: After applying mysqlgrants, quux\_ip  
> > #{quux\_ip}; current\_ip #{current\_ip}")
> > 
> > else # snipped for brevity  
> > end  
> > end  
> > action :create  
> > end
> > 
> > Thanks!  
> > kallen

---

<div class="post-metadata">

**Author:** ![Lucas\_Hrabovsky](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@Lucas\_Hrabovsky](https://discourse.chef.io/u/Lucas_Hrabovsky)\
**Post date:** [December 5, 2013, 7:36pm UTC](https://discourse.chef.io/t/nomethoderror-for-lwrp-within-a-ruby-block/4848/4 "2013-12-05T19:36:03Z")

</div>

If your able to now get access to your LWRP and hitting the problem of things not running in  
the converge, have a look at converge\_by  
[http://docs.opscode.com/lwrp\_custom\_provider\_ruby.html#converge-by](http://docs.opscode.com/lwrp_custom_provider_ruby.html#converge-by)

Here's an example from my app cookbook [How to use converge\_by in Chef LWRP's. This is from an app cookbook I forked from the main opscode application cookbook but stripped way down. · GitHub](https://gist.github.com/imlucas/7812280)

On Thursday, December 5, 2013 at 2:17 PM, [kallen@groknaut.net](mailto:kallen@groknaut.net) wrote:

> Thanks for the response. I forgot chef DSL isn't available within a ruby\_block.  
> Basically, I'm trying to get my recipe actions executing in the right order,  
> using the chef tools as I understand them so far. I'll probably try run\_context  
> today.
> 
> Given my cookbook, the run order I desire is:
> 
> 1. Start mysql
> 2. Wait for innodb recovery to complete (i.e. wait for mysql to respond to queries).
> 3. Query a value from mysql
> 4. Take action on that value using my LWRP
> 
> But the run order that actually happened before I tried putting 3 and 4 into  
> a ruby\_block was:
> 
> 1. Query a value from mysql (got executed at compile phase)
> 2. Take action on that value using my LWRP (got executed at compile phase)
> 3. Start mysql (got executed at convergence phase)
> 4. Wait for innodb recovery to complete (i.e. wait for mysql to respond to queries). (got executed at convergence phase)
> 
> Items executing at compile phase rather than convergence phase is working  
> against me, I feel. I'll keep trying.
> 
> thx,  
> kallen
> 
> On Wed, 04 Dec 2013, Brian Fletcher wrote:
> 
> > Hi Callen,
> > 
> > When inside a ruby\_block the chef DSL doesn't work. You need to use pure  
> > ruby. Here is an example of how you can execute a resource from a  
> > ruby\_block. The cookbook is called 'test' and the lwrp is called 'mine'.
> > 
> > ruby\_block 'dd' do  
> > block do  
> > mine = Chef::Resource::TestMine.new('bb', run\_context)  
> > mine.run\_action(:create)  
> > end  
> > action :create  
> > end
> > 
> > You will need something like the following. The lwrp name is turned into  
> > camel case.
> > 
> > mysqlacl = Chef::Resource::ClonerDbSvcMysqlacl("mysqlgrants", run\_context)  
> > mysqlacl.ipv4\_address(quux\_ip)  
> > ?
> > 
> > mysqlacl.run\_action(:create\_acl)
> > 
> > Regarding whether its the right thing to do, I try to avoid them if  
> > possible. This is because it is difficult to make assertions about the  
> > actions executed within a ruby\_block using chefspec (unit testing for  
> > chef).
> > 
> > Thanks,
> > 
> > Brian
> > 
> > On 04/12/2013 19:06, "[kallen@groknaut.net](mailto:kallen@groknaut.net) ([mailto:kallen@groknaut.net](mailto:kallen@groknaut.net))" \<[kallen@groknaut.net](mailto:kallen@groknaut.net) ([mailto:kallen@groknaut.net](mailto:kallen@groknaut.net))\> wrote:
> > 
> > > Hiya,
> > > 
> > > How do I make an LWRP that I created available in a recipe within a  
> > > ruby\_block?  
> > > It's not working for me.
> > > 
> > > [2013-12-04T00:13:14+00:00] DEBUG: Re-raising exception: NoMethodError -  
> > > ruby\_block[do stuff] (cloner::grants line 30) had an error:  
> > > NoMethodError: undefined method `cloner_db_svc_mysqlacl' for Chef::Resource::RubyBlock /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/resource. rb:294:in `method\_missing'  
> > > /var/cache/chef/cookbooks/cloner/recipes/grants.rb:67:in `block (2  
> > > levels) in from\_file'
> > > 
> > > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider/  
> > > ruby\_block.rb:33:in `call'
> > > 
> > > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider/  
> > > ruby\_block.rb:33:in `block in action\_run'
> > > 
> > > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/mixin/why  
> > > \_run.rb:52:in `call'
> > > 
> > > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/mixin/why  
> > > \_run.rb:52:in `add\_action'
> > > 
> > > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider.  
> > > rb:149:in `converge\_by'
> > > 
> > > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider/  
> > > ruby\_block.rb:32:in `action\_run'
> > > 
> > > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/provider.  
> > > rb:114:in `run\_action'
> > > 
> > > /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.2/lib/chef/resource.  
> > > rb:625:in `run\_action'  
> > > ...
> > > 
> > > Afaict, the recipe code needs to execute during the convergence phase of  
> > > the  
> > > chef-client run. In my case, the code needs to (1) first start mysql, (2)  
> > > wait  
> > > for mysql to complete its startup (wait for innodb recovery to complete)  
> > > and (3)  
> > > then query a value from a table. (4) And then do another action depending  
> > > on the  
> > > value returned.
> > > 
> > > I tried doing the above outside a ruby\_block my first time through, then  
> > > realized #3 was executing before #2 had completed. IOW #3 was executing  
> > > at the  
> > > compile phase. So now I'm trying to put all of this into a ruby\_block,  
> > > but the  
> > > call to my LWRP is failing. (Is using a ruby\_block for this the right  
> > > answer?)
> > > 
> > > The LWRP lives in 'cloner-db-svc' cookbook. The cookbook::recipe that  
> > > calls it  
> > > is 'cloner::grants'. The cloner cookbook depends on cloner-db-svc. When  
> > > the code  
> > > runs outside of a ruby\_block, the recipe finds the LWRP method just fine,  
> > > but  
> > > the behavior I need doesn't occur.
> > > 
> > > ::Chef::Recipe.send(:include, ::Cloner::Chef::DbSvc::Helper)
> > > 
> > > ruby\_block "do stuff" do  
> > > block do  
> > > quux\_ip = search(:node, 'roles:quux').map {|server|  
> > > server['ipaddress'] }.join(",")  
> > > cli\_password = ::Cloner::Chef::DbSvc::Helper.fetchsecret( "secrets",  
> > > "#{node['cloner']['environment']}", "rootpass" )  
> > > current\_ip = %x( mysql --skip-column-names -hlocalhost -uroot  
> > > -p#{cli\_password} -e "SELECT Host FROM mysql.user WHERE  
> > > User='cloner\_admin'" )
> > > 
> > > if current\_ip.empty?  
> > > Chef::Log.debug("HIGGS-BOSON: current\_ip is empty, applying  
> > > grants.")  
> > > cloner\_admin\_pass = ::Cloner::Chef::DbSvc::Helper.fetchsecret(  
> > > "secrets", "#{node['cloner']['environment']}", "cloner\_admin\_pass" )  
> > > cloner\_proc\_pass = ::Cloner::Chef::DbSvc::Helper.fetchsecret(  
> > > "secrets", "#{node['cloner']['environment']}", "cloner\_proc\_pass" )
> > > 
> > > cloner\_db\_svc\_mysqlacl "mysqlgrants" do  
> > > action :create\_acl  
> > > ipv4\_address quux\_ip  
> > > cli\_password cli\_password  
> > > cloner\_admin\_pass cloner\_admin\_pass  
> > > cloner\_proc\_pass cloner\_proc\_pass  
> > > end  
> > > current\_ip = %x( mysql --skip-column-names -hlocalhost -uroot  
> > > -p#{cli\_password} -e "SELECT Host FROM mysql.user WHERE  
> > > User='cloner\_admin'" )  
> > > Chef::Log.debug("HIGGS-BOSON: After applying mysqlgrants, quux\_ip  
> > > #{quux\_ip}; current\_ip #{current\_ip}")
> > > 
> > > else # snipped for brevity  
> > > end  
> > > end  
> > > action :create  
> > > end
> > > 
> > > Thanks!  
> > > kallen
