notifications - Chef 'notifies :action, ' 资源', :before' work at all as it should?

标签 notifications chef-infra

我最近尝试执行一个简单的任务:如果软件包不存在,则通过从 Web 位置(内部存储库)中拉出分发并在不再需要时将其删除来安装它。

了解 :before 通知我想出了以下优雅的代码(在此示例中,变量“pkg”保留分发镜像的名称,“pkg_src_location”是我的网络存储库的 URL,“name_of_package”被命名为已安装的包):

local_image = "#{Chef::Config['file_cache_path']}/#{pkg}"

remote_file 'package_image' do
  path local_image
  source "#{pkg_src_location}/#{pkg}"
  action :nothing
end

package name_of_package do
  source local_image
  notifies :create, 'remote_file[package_image]', :before
  notifies :delete, 'remote_file[package_image]', :delayed
end

我很惊讶它不起作用......实际上'包'资源正在融合而没有创建'remote_file' - 由于源local_image没有到位而失败......

我做了一个简单的测试:
log 'before' do
  action :nothing
end

log 'after' do
  action :nothing
end

log 'at-the-end' do
  action :nothing
end

log 'main' do
  notifies :write, 'log[before]', :before
  notifies :write, 'log[at-the-end]', :delayed
  notifies :write, 'log[after]', :immediately
end

我学到的是'main'实际上收敛了两次!一次是第一次遇到,一次是在“之前”资源收敛之后......
   Recipe: notify_test::default
     * log[before] action nothing (skipped due to action :nothing)
     * log[after] action nothing (skipped due to action :nothing)
     * log[at-the-end] action nothing (skipped due to action :nothing)
     * log[main] action write

     * log[before] action write

     * log[main] action write

     * log[after] action write

     * log[at-the-end] action write

这是错误还是功能?如果这是“功能”,那真是太糟糕了,Chef 根本不应该拥有它。它的工作方式根本没用,只会浪费人们的时间......

任何对厨师有更深入了解的人都可以评论吗?有什么办法可以让 ':before' 工作吗?也许我只是在这里做错了什么?

最佳答案

更具体地说,before计时使用“为什么运行”系统来猜测资源是否需要更新。在这种情况下,包资源一开始就无效,所以whyrun 无法判断需要更新。

关于notifications - Chef 'notifies :action, ' 资源', :before' work at all as it should?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40806714/

相关文章:

chef-infra - 当没有对 erb 模板进行任何更改时,Chef 会不断重新启动服务

android - 同步作业之间的最佳时间是什么时候?

macos - comboBoxSelectionDidChange给我以前选择的值

ios - 是否可以在获得初始权限后向 UIUserNotificationCategory 添加新操作?

chef-infra - Chef 中默认的 run_list 和 '_default' 环境 run_list 有什么区别?

ruby - 如何设置对在 Chef 加载 Recipe 时不存在的 Ruby 库的依赖项?

chef-infra - 带有递归目录的 Chef 模板

ruby - 在 Chef 配方中,您如何为 Ruby 指定特定的补丁级别?

android - 如何在 Android Oreo 中的特定时间在 Android 上发出通知?

android - Webview Android App 中的网站通知