2016-02-24 42 views
2

在我的自定義廚師食譜(位於https://github.com/sanguis/chef-omeka/tree/lwrp)。從自定義資源調用時,廚師Apache2 cookbook資源無法找到服務[apache2]

我正在從自定義solo.rb配方調用的自定義資源(LWRP)中調用Apache2資源web_app。

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 

這這將返回一個錯誤:

[#] [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'

然而,當我打電話相同的資源直接定製配方here(線126)的內部工作原理。

我運行列表是波紋管

#  - 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"] 

這失敗在兩個Ubuntu的14.04和centos7。

回答

1

這是一個已知的問題,目前只有很少的解決方法。問題是使用新的自定義資源系統強制執行use_inline_resources模式,這是99%的好主意,除此之外。該模式會在自定義資源內部創建一個獨立的運行環境,以便爲通知的目的而看不到其他資源。該泊助手庫提供了一些工具來解決這個問題,但廚師核心是唯一的主要解決辦法是超級不支持(即這可能會破壞沒有出現大的版本):

web_app url do 
    # ... 
    notifies :reload, Chef.run_context.resource_collection.find('service[apache2]') 
end 
+0

所以他這樣說我創建一個我希望能夠從其他食譜中使用我的食譜資源,我應該只是做舊的LWRP風格,直到完成上述工作爲止? –

+0

以上內容不會被整理出來AFAIK,這是Chef核心團隊如何實現的系統性問題。 Poise的幫手或類似的項目可能會比Chef的內部工具更好地滿足這個用例。舊式的LWRPs會以相同的方式受到影響,除非您不使用'use_inline_resources',否則您不應該這樣做,因爲這有更多奇怪的問題。 – coderanger

+0

感謝您的信息。 –