首页 > 解决方案 > Chef 执行资源 not_if 守卫返回 1;仍然跳过

问题描述

我发现这个问题非常相似,但是我正在实例上执行测试代码,根据文档,这意味着不应该应用防护。但是,它每次都在跳过。任何帮助,将不胜感激。

厨师代码:

# Install the DNS plugin for the CLI
execute 'Install-DNS-plugin' do
  command 'akamai install dns --force'
  not_if 'akamai list | grep dns'
end

总是导致跳过:

==> default:   * execute[Install-DNS-plugin] action run
==> default:  (skipped due to not_if)

即使在实例上,保护代码返回 1:

[root@vagrant ~] $ akamai list | grep dns
[root@vagrant ~] $ echo $?
1

标签: chef-infra

解决方案


akamai cli 是否依赖特定的环境变量或 shell 初始化?not_if除非您指定它们,否则两者可能都不存在。请参阅https://docs.chef.io/resource_common/#arguments

我建议akamai list | grep dns在执行资源本身中运行以调试结果。


推荐阅读