我在 Terraform 中为 Azure VM 定义了一个 CustomScriptExtension:
resource "azurerm_virtual_machine_extension" "test" {
name = "WinRM"
location = "South Central US"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_machine_name = "${azurerm_virtual_machine.test.name}"
publisher = "Microsoft.Compute"
type = "CustomScriptExtension"
type_handler_version = "1.8"
settings = <<SETTINGS
{
"fileUris": "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1",
"commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File ConfigureRemotingForAnsible.ps1"
}
SETTINGS
}
但是我得到了(同样的错误在 VM 扩展的 Azure 门户中可见):
azurerm_virtual_machine_extension.test:compute.VirtualMachineExtensionsClient#CreateOrUpdate:发送请求失败:StatusCode = 200 - 原始错误:长时间运行的操作以状态“失败”终止:代码 =“VMExtensionProvisioningError”消息 =“VM 在处理扩展 'WinRM 时报告失败'。错误消息:\“无效的处理程序配置。退出。错误消息:期望状态“元素”。遇到名称为“文本”、命名空间“”的“文本”。\"。"
作为Azure 部署执行的相同参数没有问题(相关摘录如下):
"fileUris": {
"type": "string",
"defaultValue": "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1",
"metadata": {
"description": "The uri list of files. Split by a space."
}
},
"settings": {
"fileUris": "[split(parameters('fileUris'), ' ')]",
"commandToExecute": "[parameters('commandToExecute')]"
}
我错过了什么,还是 Terraform 中的错误?
一些调试:
如果我将设置替换为:
{ "commandToExecute": "mkdir C:\\Test" }
目录被创建,所以问题出在
fileUris
.如果我
fileUris
在设置 JSON 中替换为fileUri
(这应该是错误的):{ "fileUri": "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1", "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File ConfigureRemotingForAnsible.ps1" }
没有
Encountered 'Text' with name '', namespace ''. \".
错误,powershell.exe
火灾和报告丢失ConfigureRemotingForAnsible.ps1
。