chef receipe notify problem

dafire's Avatar

dafire

05 Aug, 2011 11:05 AM

Hi,

I try to create a receipt which updates a configuration file in the deployed apps and, if the configuration was changed clears the caches folders of the app.

I found some code at http://wiki.opscode.com/display/chef/Resources#Resources-Notifications

template "/etc/nagios3/configures-nagios.conf" do
  # other parameters
  notifies :run, "execute[test-nagios-config]", :immediately
end

# this will fail and prevent us from restarting nagios if we broke the config
execute "test-nagios-config" do
  command "nagios3 --verify-config"
  action :nothing
end

This is my code:

node[:deploy].each do |application, deploy|

  template "#{deploy[:deploy_to]}/current/app/config/parameters.ini" do
    source "parameters.ini.erb"
    mode "0660"
    group deploy[:group]
    owner deploy[:user]
    variables(:database => deploy[:database])

    only_if do
      File.directory?("#{deploy[:deploy_to]}/current/app/config")
    end

    notifies :run, "execute[clear_cache]"

  end

  execute "clear_cache" do
    command "rm -rf  #{deploy[:deploy_to]}/current/app/cache/*"
    action :nothing
  end

end

and the error is:

DEBUG: Re-raising exception: NoMethodError - undefined method `run_action' for "execute[clear_cache]":String

Sorry, I've not done much with ruby, yet :)
Thanks for your help.

  1. Support Staff 2 Posted by Jonathan Weiss on 05 Aug, 2011 11:29 AM

    Jonathan Weiss's Avatar

    Can you try

    notifies :run, resources(:execute => "clear_cache")
    

    instead of

    notifies :run, "execute[clear_cache]"
    

    Also, I would make sure, that the resource is unique per app, e.g:

    node[:deploy].each do |application, deploy|
    
      template "#{deploy[:deploy_to]}/current/app/config/parameters.ini" do
        source "parameters.ini.erb"
        mode "0660"
        group deploy[:group]
        owner deploy[:user]
        variables(:database => deploy[:database])
    
        only_if do
          File.directory?("#{deploy[:deploy_to]}/current/app/config")
        end
    
        notifies :run, resources(:execute => "clear_cache_#{application}")
    
      end
    
      execute "clear_cache_#{application}" do
        command "rm -rf  #{deploy[:deploy_to]}/current/app/cache/*"
        action :nothing
      end
    
    end
    
  2. 3 Posted by dafire on 05 Aug, 2011 11:53 AM

    dafire's Avatar

    Ok .. it failed now because it won't find the execute action but after I put the execute block above the template block it works now.

    Thanks for your help and the hint with the unique identifier.

  3. Support Staff 4 Posted by Jonathan Weiss on 05 Aug, 2011 11:56 AM

    Jonathan Weiss's Avatar

    no problem, if you encounter any other issues, don't hesitate to ask.

  4. Jonathan Weiss closed this discussion on 05 Aug, 2011 11:56 AM.

Comments are currently closed for this discussion. You can start a new one.