Search code examples
powershellchef-infranewrelic

Powershell script is failing when installing new relic infrastructure agent using chef


I have MS SQL Server 2019 installed on Windows Server 2016. I am trying to install the new relic integration for SQL Server. Since before the integration part we need to install the new relic infrastructure agent. When I am using the below powershell script manually it is working fine but not working when using chef.

I am using the below Powershell script to install it using chef.

  # 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

When I am running the above script it fails and shows following error.

New Relic Error -1

After that it shows " Checking for data in New Relic " message few times and the script crashes and exit at below position when it selects MS SQL Server Integration Installer

New Relic Error -2

Any idea why it is failing using the chef and working fine manually? Thanks


Solution

  • It was not failing manually because when it asks to choose from the list of option we manually press the enter. When using chef we were not passing any argument or not controlling the option selection part. So simply passing an argument -y after install and before --skipLogging will work.