Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 通过CLI部署Azure ARM模板失败,出现.ps1脚本扩展错误_Json_Powershell_Azure_Templates_Command Line Interface - Fatal编程技术网

Json 通过CLI部署Azure ARM模板失败,出现.ps1脚本扩展错误

Json 通过CLI部署Azure ARM模板失败,出现.ps1脚本扩展错误,json,powershell,azure,templates,command-line-interface,Json,Powershell,Azure,Templates,Command Line Interface,我一直在通过VisualStudio部署我的ARM模板,带有一个自定义脚本扩展(.ps1),很好,它实际上也是通过VS编译的。但是,我一直试图通过CLI部署它,并对Azure存储位置上的.ps1文件进行了修改,以便其他没有VS的用户可以部署它。但是,每次部署失败时,都会出现错误,说明脚本没有.ps1扩展名 我的ARM模板的自定义脚本扩展部分: "name": "formatDataDisk", "type": "extensions", "location":

我一直在通过VisualStudio部署我的ARM模板,带有一个自定义脚本扩展(.ps1),很好,它实际上也是通过VS编译的。但是,我一直试图通过CLI部署它,并对Azure存储位置上的.ps1文件进行了修改,以便其他没有VS的用户可以部署它。但是,每次部署失败时,都会出现错误,说明脚本没有.ps1扩展名

我的ARM模板的自定义脚本扩展部分:

      "name": "formatDataDisk",
      "type": "extensions",
      "location": "[resourceGroup().location]",
      "apiVersion": "2016-03-30",
      "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
      ],
      "tags": {
        "displayName": "formatDataDisk"
      },
      "properties": {
        "publisher": "Microsoft.Compute",
        "type": "CustomScriptExtension",
        "typeHandlerVersion": "1.4",
        "autoUpgradeMinorVersion": true,
        "settings": {
          "fileUris": [
            "https://--MYSTORAGEACCOUNTNAME--.blob.core.windows.net/customscript/formatDataDisk.ps1"
          ],
          "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File './customscript/formatDatadisk1.ps1'"
        },
        "protectedSettings": {
          "storageAccountName": "--MYSTORAGEACCOUNTNAME--",
          "storageAccountKey": "--MYSTORAGEKEY--"
        }
CLI部署结束时,出现以下故障:

msrest.http_logger : b'{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.","details":[{"code":"Conflict","message":"{\\r\\n  \\"status\\": \\"Failed\\",\\r\\n  \\"error\\": {\\r\\n    \\"code\\": \\"ResourceDeploymentFailure\\",\\r\\n    \\"message\\": \\"The resource operation completed with terminal provisioning state \'Failed\'.\\",\\r\\n    \\"details\\": [\\r\\n      {\\r\\n        \\"code\\": \\"VMExtensionProvisioningError\\",\\r\\n        \\"message\\": \\"VM has reported a failure when processing extension \'formatDataDisk\'. Error message: \\\\\\"Finished executing command\\\\\\".\\"\\r\\n      }\\r\\n    ]\\r\\n  }\\r\\n}"}]}}'
    msrest.exceptions : At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.
    Deployment failed. {
      "status": "Failed",
      "error": {
        "code": "ResourceDeploymentFailure",
        "message": "The resource operation completed with terminal provisioning state 'Failed'.",
        "details": [
          {
            "code": "VMExtensionProvisioningError",
            "message": "VM has reported a failure when processing extension 'formatDataDisk'. Error message: \"Finished executing command\"."
          }
Azure Portal在自定义脚本扩展中显示此错误:

[
    {
        "code": "ComponentStatus/StdOut/succeeded",
        "level": "Info",
        "displayStatus": "Provisioning succeeded",
        "message": ""
    },
    {
        "code": "ComponentStatus/StdErr/succeeded",
        "level": "Info",
        "displayStatus": "Provisioning succeeded",
        "message": "Processing -File ''./customscript/formatDatadisk1.ps1'' failed because the file does not have a '.ps1' extension. Specify a valid Windows PowerShell script file name, and then try again."
    }
]
我试过:

  • “commandToExecute”:“powershell.exe-执行策略不受限制-NoProfile-非交互式-文件格式DataDisk1.ps1”
  • “typeHandlerVersion”:“1.9”
  • 将文件重新上载到新的存储位置,更改子文件夹路径和访问密钥
  • 我的剧本似乎符合

如果路径错误,您需要省略路径中的容器,我们将非常感谢您提供的任何指导

"commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File './formatDatadisk1.ps1'"
它总是将下载的文件放在同一个目录中,没有嵌套的文件夹

下面是对我有效的片段:

"properties": {
    "publisher": "Microsoft.Compute",
    "type": "CustomScriptExtension",
    "typeHandlerVersion": "1.8",
    "autoUpgradeMinorVersion": true,
    "settings": {
        "fileUris": [
            "https://backupcicd.blob.core.windows.net/deployment/iis-preConfigureScript.ps1"
        ],
        "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File iis-preConfigureScript.ps1"
    }
}

当我在实验室测试你的模板时,我得到了和你相同的错误日志。当我删除
/customscript/
时,它对我有效

  "resources": [
    {
      "name": "[concat(parameters('virtualMachineName'), '/', 'shuitest')]",
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "location": "eastus",
      "apiVersion": "2016-03-30",
      "dependsOn": [ ],
      "tags": {
        "displayName": "shuitest"
      },
      "properties": {
        "publisher": "Microsoft.Compute",
        "type": "CustomScriptExtension",
        "typeHandlerVersion": "1.4",
        "autoUpgradeMinorVersion": true,
        "settings": {
          "fileUris": ["https://shuiwindisks928.blob.core.windows.net/vhds/open_port.ps1"]

        },
        "protectedSettings": {
          "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File open_port.ps1",
          "storageAccountName" : "shuiwindisks928",
          "storageAccountKey" : "jvYg+1aCo+d4b+FI/kdBOtE*******************+kXa0yZR5xrt7a57qgHw=="
        }
      }
    }],
更新:


您需要检查VM上的扩展日志,请参阅此。

最后,我在其他注释的帮助下解决了此问题。我使用了一个更简单的helloworld.ps1脚本进行了测试,它成功了,所以我的powershell脚本显然存在问题。在Visual Studio中创建时,会将以下内容放在顶部:

<# Custom Script for Windows #>

接下来是脚本的其余部分。一旦我删除了它并重新上传到我的StorageAccount/Container,并在commandToExecute中删除了./in,一切正常


感谢您的反馈。

我不确定它是否与此特定问题有关,但在过去3-4天的Azure自定义扩展工作中,我注意到,如果您的脚本失败一次,并且自定义扩展的ARM模板部署失败,那么您将不得不在来自Azure门户的扩展刀片,您正试图在其上运行脚本。如果您不这样做,无论您对脚本做了什么更改,自定义扩展都将继续运行旧脚本。

遗憾的是,这没有什么区别,它仍然会失败,并出现相同的错误。我仍然在这里苦苦挣扎。我将代码设置为与您的代码相同,但仍然失败,而刚才我将autoUpgradeMinorVersion设置为false,希望该版本可能不喜欢它,但它再次失败。好吧,这是我的产品代码,因此它可以工作,您可以直接使用此代码,它将工作:)只需将脚本上载到某个地方,将
fileUris
更改为指向该位置,您就很好了,很明显,您可以更改传递给
-File
的参数,您能告诉我您在这个脚本上运行的是什么apiVersion吗?“2016-04-30-preview”@Beefcake如果我使用
“commandToExecute”:“powershell.exe-ExecutionPolicy Unrestricted-NoProfile-NonInteractive-文件”“/formatDatadisk1.ps1”“
您可以尝试删除
/
。我相信它会起作用的。我以前在没有/的情况下试过,但它不起作用。不幸的是,我今天没有机会部署脚本,但明天早上我会再次尝试。@Beefcake好的,你也可以在VM中检查登录。因为这不是“解决”问题的方法。建议是有帮助的,但它并没有解决我问题的根本原因,修改了.ps1文件。@Beefcake-Hi,谢谢你的回复。如果你分享你的脚本,也许我们可以更快地解决你的问题。但我很高兴听到你解决了你的问题。我在实验室测试,我认为根本原因是你应该删除命令中的
'
powershell.exe-ExecutionPolicy Unrestricted-NoProfile-NonInteractive-File./customscript/formatDatadisk1.ps1