2

In my custom chef cookbook (located at https://github.com/sanguis/chef-omeka/tree/lwrp).

I am calling the Apache2 resource web_app from inside a custom resource (LWRP) that is being called from the custom solo.rb recipe.

    include_recipe 'apache2' 
web_app url do
  server_name url
  server_aliases aliaes
  cookbook_name 'apache2'
  docroot dir
  allow_override 'All'
  directory_index 'false'
  # notifies :reload, 'service[apache2]', :delayed
end

This this returns an error:

[#] [2016-02-23T23:02:31+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report

[#] [2016-02-23T23:02:31+00:00] ERROR: instanceomeka.dev had an error: Chef::Exceptions::ResourceNotFound: resource execute[a2enmod headers] is configured to notify resource service[apache2] with action reload, but service[apache2] cannot be found in the resource collection. execute[a2enmod headers] is defined in /tmp/kitchen/cache/cookbooks/apache2/definitions/apache_module.rb:35:in `block in from_file'

However when I call the same resource from directly inside of a custom recipe here (line 126) it works.

My run list is bellow

   #      - recipe[build-essential]
  - recipe[php::default]
  - recipe[apache2]
  - recipe[apache2::mod_rewrite]
    # - recipe[apache2::mod_expires]
  - recipe[apache2::mod_ssl]
  - recipe[apache2::mod_php5]
  - recipe[omeka::default]
  - recipe[omeka::solo]
attributes:    #      - recipe[build-essential]
  - recipe[php::default]
  - recipe[apache2]
  - recipe[apache2::mod_rewrite]
    # - recipe[apache2::mod_expires]
  - recipe[apache2::mod_ssl]
  - recipe[apache2::mod_php5]
  - recipe[omeka::default]
  - recipe[omeka::solo]
attributes: 
  machine_fqdn: omeka.dev
  machine_fqdn_as_hostname: true
  apache2:
    listen_ports: ["80", "443"]

  machine_fqdn: omeka.dev
  machine_fqdn_as_hostname: true
  apache2:
    listen_ports: ["80", "443"]

This fails on both ubuntu 14.04 and centos7.

1 Answer 1

1

This is a known issue with few workarounds for the moment. The issue is that using the new custom resource system enforces use_inline_resources mode, which is 99% a great idea except for this. That mode creates an isolated run context inside the custom resource so it can't see "out" to the other resources for the purposes of notifications. The Poise helper library offers some tools to get around this, but with Chef core the only major workaround is the super-unsupported (i.e. this might break without a major release):

web_app url do
  # ...
  notifies :reload, Chef.run_context.resource_collection.find('service[apache2]')
end
2
  • so that being said I am creating a resource in my cookbook that I want to be able to use from other cookbooks, should I just do the old LWRP style till the above is sorted out? Feb 24, 2016 at 21:27
  • The above won't be sorted out AFAIK, it's a systemic issue with how the Chef core team implements things. This use case will probably be better served by Poise's helpers or similar projects than Chef's internal tools. Old style LWRPs are affected in the same way unless you don't use_inline_resources which you shouldn't do because that has even more weird issues with sequencing.
    – coderanger
    Feb 24, 2016 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.