【问题标题】:batch not_if guard says "action run" rather than "skipped"批处理 not_if 守卫说“动作运行”而不是“跳过”
【发布时间】:2018-05-22 22:04:17
【问题描述】:

如果启用了某个安全策略,我的配方中有一个 PS 脚本会导致 chef-run 失败(基本上是this 问题)。

所以我添加了一个 not_if 保护

  powershell_script 'scheduled-tasks' do
    guard_interpreter :powershell_script
    cwd 'C:\Temp'
    code <<-EOH
      schtasks.exe /create ...
      schtasks.exe /create ...
    EOH
    not_if "(get-itemproperty 'HKLM:\\System\\CurrentControlSet\\Control\\Lsa').DisableDomainCreds -eq '1'"
  end

我正在使用 Test-Kitchin、VirtualBox 和 Windows VM。运行 powershell 命令 'getitemproperty...' 返回 True 表示它已启用,因此我不希望脚本运行并希望 Chef 说 'skipped due to not_if'。

但是,在终端输出中显示“动作运行”。

主厨运行没有失败,所以脚本无法运行,但为什么没有说“跳过”?

问候

【问题讨论】:

    标签: powershell chef-infra


    【解决方案1】:

    这是因为您在 not_if 语句中使用了双引号。尝试改用花括号或单引号。注意同样使用单引号的 Powershell 逻辑运算符:

    not_if '(Get-ItemProperty HKLM:\\System\\CurrentControlSet\\Control\\Lsa).DisableDomainCreds -eq "1"'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-04
      • 1970-01-01
      • 2013-04-01
      • 2021-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多