Chef notifies global service from LWRP provider code

I see that if service['somename']created inside LWRP with enabled use_inline_resources, this resource is not displayed in other contexts - as described here: Notify the service defined in the included LWRP recipe

I have a situation where it service['somename']is defined in the usual recipe (not in the LWRP provider). The LWRP provider then attempts to notify the service. In my example, a service is a web server, and LWRP is responsible for creating virtual hosts inside this web server.

If I use use_inline_resourcesin this provider, the code inside the provider does not see the resources defined in the global area (in the usual recipes). A cookbook with a recipe defining this service is added as depends cookbooknamein metadata.rb.

So the question is: how does it actually work use_inline_resources- the official explanation is not clear to me ( http://docs.getchef.com/lwrp_common_inline_compile.html ). This explanation says the opposite of what I see - he says:

To ensure that the embedded lightweight resource can add a top-level resource, add use_inline_resourcesto the beginning of the file

In my situation, I have a recipe:

include_recipe "web server :: install" # creates the service ['web-server']

this_cookbook_my_lwrp "sites" do # this LWRP is trying to notify the service ['web-server']
action: create | end

So, this LWRP is defined in this cookbook. And he behaves like this:

  • If LWRP contains use_inline_resources, it cannot see the service ['web-server']
  • LWRP use_inline_resources, ['web-server']

, use_inline_resources - , ?

+4
3

lrwp, :

webserver = run_context.parent_run_context.resource_collection.find('service[webserver]')
new_resource.notifies :restart, webserver
+2

, , use_inline_resources

, use_inline_resources LWRP , LWRP updated, updated. LWRP , ( ).

, LWRP, , , , LWRP ( , ). , LWRP, .

, LWRP , , LWRP . , LWRP - vhost? , LWRP -, . LWRP VHOST, / -. , , -, . service -, service , ( , LWRP, -).

mycool_vhost 'some vhost' do
  attribute value
  other_attribute value
end

service 'mywebserver' do
  subscribes :reload, "mycool_vhost[some vhost]"
end

- .

+1

use_inline_resources LWRP.

LWRP .

-, -.

, LWRP , LWRP , LWRP ( ) - LWRP.

Using use_inline_resourcesresources within LWRP can notify each other. Without use_inline_resources, they will be added to the main ones run_contextand resource_collectionduring pahse merging, and not during compilation, and usually this ends with internal notifications not working, and sometimes resources are duplicated if LWRP defines a service or resources with a fixed name.

Hope this gets a little clearer.

0
source

All Articles