poise / application_ruby

Development repository for Opscode Cookbook application_ruby
Apache License 2.0
124 stars 153 forks source link

ruby_execute does not accept notifications within an application resource definition #80

Closed rhass closed 8 years ago

rhass commented 8 years ago

I encountered an issue in which ruby_execute resources could not be called from within an application definition. The error is:

       Compiling Cookbooks...
       Converging 28 resources

       Running handlers:
       [2016-01-16T03:11:19+00:00] ERROR: Running exception handlers
       Running handlers complete
       [2016-01-16T03:11:19+00:00] ERROR: Exception handlers complete
       Chef Client failed. 0 resources updated in 02 seconds
       [2016-01-16T03:11:19+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2016-01-16T03:11:19+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2016-01-16T03:11:19+00:00] ERROR: resource git[railstutorial] is configured to notify resource ruby_execute[notify-me] with action run, but ruby_execute[notify-me] cannot be found in the resource collection. git[railstutorial] is defined in /tmp/kitchen/cache/cookbooks/poise-ruby-example/recipes/default.rb:21:in `block in from_file'

       [2016-01-16T03:11:21+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

To DRY out reproducing this issue, I created the following cookbook: https://github.com/rhass/poise-ruby-example

It should be noted that taking the ruby_execute block out of the application resource causes it to be unaware of the ruby resource for the parent_ruby and parent_bundler properties.

CC @blt04 (Also affected by this bug.)

coderanger commented 8 years ago

So this is one of the problems with the transparent rewrite stuff. Make that 'application_ruby_execute[notify-me]' and it will probably work. You can also use a more explicit style:

  r = ruby_execute 'notify-me' do
    command 'ruby -v'
    action :nothing
  end

  git my_git_resource do
    repository 'https://github.com/railstutorial/sample_app'
    destination '/srv/sample_app'
    revision 'master'
    notifies :run, r
    notifies :run, "execute[this-works-though]"
    action :sync
  end
coderanger commented 8 years ago

To explain in more detail, inside the application resource it will transparently rewrite resource to their application_* variant to allow automatic integration like how application_ruby_execute knows about app-level config data.

rhass commented 8 years ago

Thanks! Both of these suggestions worked; one thing I noted is the more explicit style needs to have the object defined before the notifying resource, just as you showed the suggested example.

Thanks again! You rock! :metal: