【问题标题】:Powershell script is failing when installing new relic infrastructure agent using chef使用 Chef 安装新的 Relic 基础架构代理时,Powershell 脚本失败
【发布时间】:2021-07-29 00:07:48
【问题描述】:

我在 Windows Server 2016 上安装了 MS SQL Server 2019。我正在尝试为 SQL Server 安装新的遗物集成。由于在集成部分之前,我们需要安装新的 relic 基础设施代理。当我手动使用以下 powershell 脚本时,它可以正常工作,但在使用 chef 时无法正常工作。

我正在使用下面的 Powershell 脚本来安装它。

  # Install New Relic
  powershell_script 'new-relic-bootstrap' do
    code <<-PS
        [Net.ServicePointManager]::SecurityProtocol = 'tls12, tls'
        (New-Object System.Net.WebClient).DownloadFile("https://github.com/newrelic/newrelic-cli/releases/latest/download/NewRelicCLIInstaller.msi", "$env:TEMP\\NewRelicCLIInstaller.msi")
        
        msiexec.exe /qn /i $env:TEMP\\NewRelicCLIInstaller.msi | Out-Null
        
        $env:NEW_RELIC_API_KEY='ABC'
        $env:NEW_RELIC_ACCOUNT_ID='XYZ'
        
        # Prompting for input when userdata reaches this point
        & 'C:\\Program Files\\New Relic\\New Relic CLI\\newrelic.exe' install --skipLoggingInstall
        
        # Set hostname
        cd "C:\\Program Files (x86)\\ScaleFT\\"
        $sftinfo = ./sftd.exe --debug-device-info --conf C:\\Windows\\System32\\config\\systemprofile\\AppData\\Local\\ScaleFT\\sftd.yaml | ConvertFrom-Json
        $name = $sftinfo.canonical_name + "-" + ($sftinfo.alt_names).split("-")[0] + " (" + ($sftinfo.alt_names).split("-")[1] + ")"
        Add-Content -Path "C:\\Program Files\\New Relic\\newrelic-infra\\newrelic-infra.yml" -Value "display_name: $name"
        
        # Restart service
        Get-Service -Name newrelic-infra | Restart-Service
        
    PS
    guard_interpreter :powershell_script
  end

当我运行上述脚本时,它会失败并显示以下错误。

之后它会显示“Checking for data in New Relic”消息几次,当它选择 MS SQL Server Integration Installer 时脚本崩溃并退出到下面的位置

知道为什么使用厨师失败并且手动工作正常吗?谢谢

【问题讨论】:

  • 脚本是否需要用户输入?该错误还表明C:\Program Files\New Relic\... 的路径(或部分)不存在。 chef-client 运行后是否存在此路径?
  • @seshadri_c 当我们手动运行它时,它需要像主机、用户名和密码这样的输入。但是当你使用 chef 运行时,你会在 infra.yml 文件中定义所有这些输入
  • 目前尚不清楚C:\Program Files\New Relic 路径在到达Add-Content 步骤时是否可用。至少这是第一个错误似乎在抱怨的。
  • @seshadri_c 如果路径有问题,为什么手动运行时不显示错误。

标签: powershell chef-infra newrelic


【解决方案1】:

它没有手动失败,因为当它要求从选项列表中进行选择时,我们手动按下回车键。使用 chef 时,我们没有传递任何参数或没有控制选项选择部分。因此,只需在 install 之后和 --skipLogging 之前传递一个参数 -y 即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 2014-02-12
    相关资源
    最近更新 更多