popularity question answers views user  
0
Custom provider not working

Hi Everyone,

I am trying to add a custom chef provider — Chef::Provider::Tarball based on Chef::Provider::Git.

For some reason it does not want to work. I added:

/usr/lib/ruby/vendor_ruby/chef/provider/tarball.rb

And also added reference to Chef::Provider::Tarball in /usr/lib/ruby/vendor_ruby/chef/provider/deploy.rb and /usr/lib/ruby/vendor_ruby/chef/providers.rb:

require “chef/provider/tarball”

The error message I get is FATAL: NameError: uninitialized constant Chef::Provider::Tarball

Here is the full stack:

https://gist.github.com/7aa71a2088c5ec36d011

Any ideas what I could be missing?

more →
0 232  
0
Preventing an infinite notification loop with custom LWRP

Hi,

I’ve built an LWRP that handles various tasks related to configuring and restarting my application (in order to re-use the actions between the deploy resource which I use in production and a separate recipe that runs the same steps on a local checkout for developer use).

I’m using the notifying_action pattern from http://realityforge.org/code/2012/07/17/lwrp-notify-on-changed-resources.html so that my app resource is marked as updated when any of the child resources change.

As part of this, I have a few actions that need to always notify a :clear_cache action also in the same resource. For example:

notifying_action :configure do

  app_root = @new_resource.app_root
  # Always trigger clear_cache from here if resources change
  @new_resource.notifies :clear_cache,
      @new_resource.resources(:my_app => app_root), 
     :immediately

  # ~~ execute resources that provision my config files ~~~
end

# Clear the caches and restart apache
notifying_action :clear_cache do
  app_root = @new_resource.app_root

  # Always restart Apache if the cache is cleared so that 
  # APC picks up new files
  @new_resource.notifies :restart, 
      @new_resource.resources(:service => "apache2")

  # ~~~ clear the cache
end

I am scheduling the :clear_cache action for :immediately as I need it to run before the apache restart which has usually already been queued by earlier recipes.

However, this causes an infinite loop – :clear_cache executes, but because it’s in the same resource that was earlier configured to execute :clear_cache it repeats.

The only way I’ve found to resolve this is in :clear_cache to add:

notifying_action :clear_cache do
  #  ~~~~

  # Remove any immediate notification for the clear_cache 
  # actions to avoid recursive loops
  # - this is rather unpleasant, but works.
  run_context.immediate_notification_collection[@new_resource.to_s].delete_if do | notification |
    delete = (notification.action == :clear_cache)
    if (delete)
      Chef::Log.info("Cancelled queued notification for my_app :clear_cache as it is already running")
    end
    delete
  end

This feels fairly unclean, though it has the desired effect. But is there a better way either to remove the notification, or to schedule a delayed notification but ensure that it comes before the apache restart?

Thanks,

Andrew

more →
0 66