azure - 无法使用适用于 Windows 的 Azure 规模集扩展运行命令

标签 azure powershell terraform

我正在使用 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/

相关文章:

c# - 使用 PCL 和 Xamarin 对 Azure 移动服务执行单元测试时程序集版本不匹配

Azure 搜索返回不正确的结果

c# - 缺少 Microsoft.WindowsAzure.ServiceRuntime.RoleEntryPoint 的编译错误

powershell - 有什么方法可以引用管道中的前一个对象吗?

terraform - 如何销毁 Terraform 管理的默认安全组中的规则?

terraform - 错误 : Unsupported attribute. 此对象没有名为 "nsg_name"的属性

azure - 用于模拟的 Windows Azure

.net - Powershell 函数参数类型 System.ConsoleColor - 函数参数列表中缺少 ')'

powershell - 在5GB可用空间可用之前,如何删除LRU文件夹?

terraform - 计划错误 : Cloud Resource Manager API has not been used