我正在使用 terraform 启动一些适用于 Windows 的 Azure Scale 集。我编写了以下代码来更新 terraform 创建的虚拟机的动态 IP。
publisher = "Microsoft.Compute"
settings = jsonencode({
commandToExecute = "powershell.exe (((Get-Content -path C:\\Nomad\\agent\\agent.hcl -Raw) -replace '108.98.16.4','${data.azurerm_network_interface.main.private_ip_address}'| Set-Content -Path C:\\Nomad\\agent\\agent.hcl) | sc.exe start Nomad"
})
但它抛出以下错误:
Error: Code="VMExtensionProvisioningError" Message="VM has reported a failure when processing extension 'joinNomadNodes'. Error message: \"Command execution finished, but failed because it returned a non-zero exit code of: '255'. The command had an error output of: ''Set-Content' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n'\"\r\n\r\nMore information on troubleshooting is available at https://aka.ms/VMExtensionCSEWindowsTroubleshoot "
现在,如果我手动运行该命令,它的运行不会出现任何错误:
powershell.exe (((Get-Content -path C:\\Nomad\\agent\\agent.hcl -Raw) -replace '108.98.16.4','178.98.16.5'| Set-Content -Path C:\\Nomad\\agent\\agent.hcl) | sc.exe start Nomad"
最佳答案
我在“|”之前添加了转义字符“^” ..现在运行良好。
发布者=“Microsoft.Compute” 设置 = jsonencode({ commandToExecute = "powershell.exe (((Get-Content -path C:\Nomad\agent\agent.hcl -Raw) -replace '108.98.16.4','${data.azurerm_network_interface.main.private_ip_address}'^| 设置-Content -Path C:\Nomad\agent\agent.hcl) ^| sc.exe 启动 Nomad)" })
关于azure - 无法使用适用于 Windows 的 Azure 规模集扩展运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62159235/