0

我在 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

4

2 回答 2

2

错误消息:\“无效的处理程序配置。退出。错误消息:预期状态'元素'..遇到名称为'',命名空间''的'文本'。\“。”

据我所知,值类型fileUris应该是数组,我已经使用 Azure 部署对其进行了测试,如果我配置fileUris为字符串值,那么我可能会得到与您提供的相同的错误。

在此处输入图像描述

更新

fileUris应该如下所示:

"settings": {
  "fileUris": [
    "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1"
  ],
  "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File ConfigureRemotingForAnsible.ps1"
}
于 2017-02-20T03:40:10.300 回答
1

这是一个 terraform 示例,只需复制粘贴它...我评论了 RG 部分以及位置(根据情况,您可能不需要它):

    resource "azurerm_virtual_machine_extension" "win-installansibleclient" {
        name                  = "${var.current-name-convention-core-module}-mtwin-installansibleclient"
        #location              = "${var.preferred-location-module}" 
        #resource_group_name   = "${var.current-name-convention-core-module}-rg"
        virtual_machine_id = "${azurerm_virtual_machine.dcaddns-w2k16.id}"
        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
    }
于 2020-06-08T18:14:44.303 回答