我在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 - 原始错误:长时间运行操作终止,状态为&#39;失败&#39;:代码=&#34; VMExtensionProvisioningError&#34;消息=&#34; VM在处理扩展&#39; WinRM&#39;时报告失败。错误消息:\&#34;无效的处理程序配置。退出。错误消息:期待状态&#39;元素&#39; ...遇到&#39;文字&#39;名称&#39;&#39;,名称空间&#39;&#39;。 \&#34;&#34;
与Azure deployment执行的相同参数无问题(下面的相关摘录):
"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
。
如果我将设置JSON中的fileUris
替换为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
。
答案 0 :(得分: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"
}
答案 1 :(得分:1)
这是一个地形示例,只需将其复制粘贴...我评论了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
}