【问题标题】:Chef, Apache2 cookbook ressource fails to find service[apache2] when called from a custom resourceChef,Apache2 食谱资源在从自定义资源调用时无法找到服务 [apache2]
【发布时间】:2016-06-07 00:55:44
【问题描述】:

在我的定制厨师食谱中(位于https://github.com/sanguis/chef-omeka/tree/lwrp)。

我正在从自定义 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] 致命:如果您提交错误报告,请提供 stacktrace.out 文件的内容

[#] [2016-02-23T23:02:31+00:00] 错误:instanceomeka.dev 出现错误:Chef::Exceptions::ResourceNotFound: resource execute[a2enmod headers] 配置为通知资源服务[apache2] 执行重新加载操作,但在资源集合中找不到 service[apache2]。 execute[a2enmod headers] 定义在 /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 上都失败了。

【问题讨论】:

    标签: apache service chef-infra cookbook lwrp


    【解决方案1】:

    这是一个已知问题,目前几乎没有解决方法。问题是使用新的自定义资源系统会强制执行use_inline_resources 模式,除此之外,这是 99% 的好主意。该模式在自定义资源内创建了一个隔离的运行上下文,因此它无法看到其他资源的“外部”以用于通知目的。 Poise 帮助程序库提供了一些工具来解决这个问题,但是对于 Chef 核心,唯一的主要解决方法是超级不受支持(即,如果没有主要版本,这可能会中断):

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

    【讨论】:

    • 所以说我正在我的食谱中创建一个我希望能够从其他食谱中使用的资源,我是否应该只使用旧的 LWRP 样式,直到解决上述问题?
    • AFAIK 不会对以上内容进行整理,这是 Chef 核心团队如何实现事物的系统性问题。 Poise 的助手或类似项目可能比 Chef 的内部工具更好地服务于这个用例。旧式 LWRP 会以同样的方式受到影响,除非您不 use_inline_resources,否则您不应该这样做,因为这会导致更奇怪的排序问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    相关资源
    最近更新 更多