powershell - 以小型 powershell 脚本开头的 Chef Cookbook,需要将返回的整数值传递给 Chef

标签 powershell chef-infra cookbook

我正在尝试完成某人的 Recipe ,并且我需要能够让 Chef 从此脚本中提取返回的整数 0(一些细节已被删除)关于 Chef 中可能起作用的任何建议?我已经在 Chef 中添加了 Powershell 模块,特别是我在询问 Chef 解析这些数据的顺序 - 就像在 action: item 中将这个变量交给......谢谢。

include_recipe "chef_handler

powershell_script do
  code <<-EOH
  ###############
  # 
  # Description:
  # Returns 1 if any share or share path allow read/write by the 'Everyone' group (fail)
  # Returns 0 if this condition is not found (pass)


  Try
  {
    #get all shares
    $shares = e | Select-Object Name,Path
    if($shares)
    {
      Foreach ($share in $shares)
      {
        #check everyone permissions
        $shareAccounts = -Name $share.Name
        Foreach ($account in $shareAccounts)
        {
          If ($account.AName -eq 'Everyone')
          {
            return 1
          }
        }

        #check 
        $volumePerm = Get-ACL $share.Path
        if ($volume.Access.Where({$Reference -eq 'Everyone'}))
        {
          return 1
        }
      }
    }
    else
    return 0


    #loop through each share checking for 'Everyone'
    # pass the return values send to Chef or something else.
  }

  {
    #build error message
  }
  Finally
  {
    #return final message
  }
  EOH

  fail "Instance has failed the OpenShares check" if code == 1

end

最佳答案

Chef 资源没有输出值。如果 PowerShell 脚本失败,它将中止 Chef 运行,否则将继续。

关于powershell - 以小型 powershell 脚本开头的 Chef Cookbook,需要将返回的整数值传递给 Chef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37647749/

相关文章:

PowerShell "get-childitem2"大小超过 ~3.5gb

chef-infra - 使用修改后的 opsworks 部署 cookbook 不可变对象(immutable对象)错误

ruby - 解析运行列表的 Recipe 时出错 : missing cookbooks: No such Cookbooks

chef-infra - 通过 Vagrant + Chef 安装多个包

powershell - 使用多行命令参数批量启动 PowerShell

powershell - Invoke-Sqlcmd 无法运行

python - 如何直接从 python 脚本修改 Windows 10 路径变量

attributes - Chef ,覆盖不适用于 Recipe 的属性

ruby - Chef Recipe 如何从数据包中获取/检索参数?

ruby - ChefSpec 和 Ark 资源测试