【问题标题】:Failing to deploy the Azure resource manager template未能部署 Azure 资源管理器模板
【发布时间】:2019-11-16 09:03:33
【问题描述】:

我正在尝试创建一个 azure 资源管理器模板来创建应用服务计划和应用服务。

但是。当我尝试部署模板时,出现以下错误,

17:40:27 - The following parameter values will be used for this operation:
   17:40:27 -     setup-sites-non-prod-service-planName: setup-sites-non-prod-service-plan
   17:40:27 -     setup-sites-non-prod-service-planSkuName: F1
   17:40:27 - Build started.
   17:40:27 - Project "ARM_OnlineSetup.deployproj" (StageArtifacts target(s)):
   17:40:27 - Project "ARM_OnlineSetup.deployproj" (ContentFilesProjectOutputGroup target(s)):
    17:40:27 - Done building project "ARM_OnlineSetup.deployproj".
    17:40:27 - Done building project "ARM_OnlineSetup.deployproj".
    17:40:27 - Build succeeded.
    17:40:27 - Launching PowerShell script with the following command:
    17:40:27 - 'C:\Users\manjunathj\Documents\Study\ARM_OnlineSetup\bin\Debug\staging\ARM_OnlineSetup\Deploy-AzureResourceGroup.ps1' -StorageAccountName '' -ResourceGroupName 'setup-sites-non-prod-resource-group' -ResourceGroupLocation 'australiasoutheast' -TemplateFile 'C:\Users\manjunathj\Documents\Study\ARM_OnlineSetup\bin\Debug\staging\ARM_OnlineSetup\azuredeploy.json' -TemplateParametersFile 

  'C:\Users\manjunathj\Documents\Study\ARM_OnlineSetup\bin\Debug\staging\ARM_OnlineSetup\azuredeploy.parameters.json' -ArtifactStagingDirectory '.' -DSCSourceFolder '.\DSC'
    17:40:28 - [ERROR] Get-AzureRmEnvironment : The term 'Get-AzureRmEnvironment' is not recognized 
    17:40:28 - [ERROR] as the name of a cmdlet, function, script file, or operable program. Check the 
    17:40:28 - [ERROR] spelling of the name, or if a path was included, verify that the path is 
    17:40:28 - [ERROR] correct and try again.
    17:40:28 - [ERROR] At line:1 char:176
    17:40:28 - [ERROR] + ... 'true' }; if ((Get-AzureRmEnvironment -Name 'AzureCloud') -eq $null) { 
    17:40:28 - [ERROR] Set-Azure ...
    17:40:28 - [ERROR] +                    ~~~~~~~~~~~~~~~~~~~~~~
    17:40:28 - [ERROR]     + CategoryInfo          : ObjectNotFound: (Get-AzureRmEnvironment:String)  
    17:40:28 - [ERROR]    [], CommandNotFoundException
    17:40:28 - [ERROR]     + FullyQualifiedErrorId : CommandNotFoundException
    17:40:28 - [ERROR]  
    17:40:28 - [ERROR] Add-AzureRMAccount : The term 'Add-AzureRMAccount' is not recognized as the 
    17:40:28 - [ERROR] name of a cmdlet, function, script file, or operable program. Check the 
    17:40:28 - [ERROR] spelling of the name, or if a path was included, verify that the path is 
    17:40:28 - [ERROR] correct and try again.
    17:40:28 - [ERROR] At line:1 char:602
    17:40:28 - [ERROR] + ... ws.net/'  }; ((Add-AzureRMAccount -SubscriptionId 
    17:40:28 - [ERROR] 'fa801c3f-d70d-49cf-84fe-1cc1d ...
    17:40:28 - [ERROR] +                    ~~~~~~~~~~~~~~~~~~
    17:40:28 - [ERROR]     + CategoryInfo          : ObjectNotFound: (Add-AzureRMAccount:String) [],  
    17:40:28 - [ERROR]    CommandNotFoundException
    17:40:28 - [ERROR]     + FullyQualifiedErrorId : CommandNotFoundException
    17:40:28 - [ERROR]  
    17:40:28 - [ERROR] C:\Users\manjunathj\Documents\Study\ARM_OnlineSetup\bin\Debug\staging\ARM_Onlin
    17:40:28 - [ERROR] eSetup\Deploy-AzureResourceGroup.ps1 : The term 'New-AzureRmResourceGroup' is 
    17:40:28 - [ERROR] not recognized as the name of a cmdlet, function, script file, or operable 
    17:40:28 - [ERROR] program. Check the spelling of the name, or if a path was included, verify 
    17:40:28 - [ERROR] that the path is correct and try again.
    17:40:28 - [ERROR] At line:1 char:3434
    17:40:28 - [ERROR] + $UI = 'VS-'; if (!(Test-Path 'C:\Users\manjunathj\AppData\Roaming\Windows 
    17:40:28 - [ERROR] Azure  ...
    17:40:28 - [ERROR] + 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    17:40:28 - [ERROR] ~~~
    17:40:28 - [ERROR]     + CategoryInfo          : ObjectNotFound: (New-AzureRmResourceGroup:String 
    17:40:28 - [ERROR]    ) [Deploy-AzureResourceGroup.ps1], CommandNotFoundException
    17:40:28 - [ERROR]     + FullyQualifiedErrorId : CommandNotFoundException,Deploy-AzureResourceGro 
    17:40:28 - [ERROR]    up.ps1
    17:40:28 - [ERROR]  
    17:40:28 - 
    17:40:28 - Deploying template using PowerShell script failed.

PFB 我的模板的 json 文件,

{  
 "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
 "contentVersion": "1.0.0.0",
 "parameters": {
 "setup-sites-non-prod-service-planName": {
  "type": "string",
  "defaultValue": "setup-sites-non-prod-service-plan",
  "minLength": 1
 },
"setup-sites-non-prod-service-planSkuName": {
  "type": "string",
  "defaultValue": "F1",
  "allowedValues": [
    "F1",
    "D1",
    "B1",
    "B2",
    "B3",
    "S1",
    "S2",
    "S3",
    "P1",
    "P2",
    "P3",
    "P4"
  ],
  "metadata": {
    "description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
  }
}
},
"variables": {
"setup-remserv-com-au-npName": "[concat('setup-remserv-com-au-np', uniqueString(resourceGroup().id))]"
},
"resources": [
{
  "name": "[variables('setup-remserv-com-au-npName')]",
  "type": "Microsoft.Web/sites",
  "location": "[resourceGroup().location]",
  "apiVersion": "2015-08-01",
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverfarms', parameters('setup-sites-non-prod-service-planName'))]"
  ],
  "tags": {
    "[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', parameters('setup-sites-non-prod-service-planName')))]": "Resource",
    "displayName": "setup-remserv-com-au-np"
  },
  "properties": {
    "name": "[variables('setup-remserv-com-au-npName')]",
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('setup-sites-non-prod-service-planName'))]"
  }
},
{
  "name": "[parameters('setup-sites-non-prod-service-planName')]",
  "type": "Microsoft.Web/serverfarms",
  "location": "[resourceGroup().location]",
  "apiVersion": "2015-08-01",
  "sku": {
    "name": "[parameters('setup-sites-non-prod-service-planSkuName')]"
  },
  "dependsOn": [ ],
  "tags": {
    "displayName": "setup-sites-non-prod-service-plan"
  },
  "properties": {
    "name": "[parameters('setup-sites-non-prod-service-planName')]",
    "numberOfWorkers": 1
  }
}
],
"outputs": {}
}

【问题讨论】:

标签: azure powershell azure-resource-manager


【解决方案1】:

您需要获取 Azure RM 模块。打开你的 Powershell 并执行以下命令:

Install-Module AzureRM

然后做:

Import-Module AzureRM

您可以从 Powershellgallery 获得它: https://www.powershellgallery.com/packages/AzureRM/6.13.1

【讨论】:

    【解决方案2】:

    我在使用来自 github 的 Az 模块和部署脚本 (Deploy-AzureResourceGroup.ps1) 时遇到了同样的问题。部署脚本仍然引用 AzureRm 模块,因为我猜这部分代码尚未在 github 上更新。我用

    替换了以下代码
    #Requires -Module AzureRM.Resources
    #Requires -Module Azure.Storage
    #Requires -Module @{ModuleName="AzureRm.Profile";ModuleVersion="3.0"}
    

    这段代码

    #Requires -Module Az.Resources
    #Requires -Module Az.Storage
    #Requires -Module @{ModuleName="Az.Accounts";ModuleVersion="1.6.4"}
    

    并将所有 Get-AzureRmResourceGroup 引用替换为 Get-AzResourceGroup 并将引用 Test-AzureRmResourceGroupDeployment 替换为 Test-AzResourceGroupDeployment 在 Deploy-AzureResourceGroup.ps1 代码中。

    【讨论】:

      猜你喜欢
      • 2020-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-29
      • 2015-11-20
      • 1970-01-01
      相关资源
      最近更新 更多