在我们的一个项目中,我们正在尝试在 Azure 上自动部署云组件。对于大多数组件(基本上所有 ARM 组件,如 Redis、服务总线、应用服务等)我们能够使用 ARM 模板和 Powershell 脚本来实现它。
然而,我们却陷入了困境云服务(经典)成分。云服务组件中仅包含WebRole,无需发放VM。
我们可以采用经典的部署模型,即在 power shell 中使用 ASM 命令。但由于 ARM 模型支持从 azure 门户进行配置和部署,因此我想知道 ARM REST API 也必须对此组件提供开箱即用的支持。我试图弄清楚但找不到任何相关文档。
到目前为止我已经尝试过的
Azure 模板 (AzureDeploy.json)
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"parameters": {
"name": {
"type": "string"
},
"location": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "2014-06-01",
"name": "[parameters('name')]",
"location": "[parameters('location')]",
"type": "Microsoft.ClassicCompute/domainNames"
}
]
}
Powershell脚本:
Param(
[string] $ResourceGroupLocation = 'South India',
[string] $ResourceGroupName = 'FreeTrial',
[string] $TemplateFile = 'AzureDeploy.json'
)
$TemplateFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $TemplateFile))
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force -ErrorAction Stop
New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $TemplateFile).BaseName + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) `
-ResourceGroupName $ResourceGroupName `
-TemplateFile $TemplateFile `
-Force -Verbose
If I try to execute the above script, execution gets stuck at Checking deployment for an hour or so and have to manually kill the script execution.
.
但是,如果我在 power shell 中运行以下命令,它会成功在门户中创建资源:
New-AzureRmResource -位置“印度南部”-ResourceName
“cloudsmplservice”-资源类型
“Microsoft.ClassicCompute/domainNames”-ResourceGroupName“FreeTrial”
但我不明白 ARM 模板方法有什么问题。有人可以指导我解决第一种方法中的问题吗?
附录:
我发现了一个奇怪的行为。如果我在资源定义中对资源名称值进行硬编码或在 powershell 提示时传递它,则部署工作正常。
但是,如果我为参数设置一些默认值或通过参数文件传递它,它就不起作用。
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"cloudName": {
"type": "string",
"defaultValue": "cloudsrvc"
}
},
"resources": [
{
"apiVersion": "2015-06-01",
"name": "[parameters('cloudName')]",
"location": "[resourceGroup().location]",
"type": "Microsoft.ClassicCompute/domainNames"
}
]
}
附录2:
似乎是一些 powershell 配置问题。将向 Azure 团队报告更多详细信息。到目前为止,我们可以通过简单的步骤来重现它:
- 在天蓝色中创建了一个新的虚拟机。
- 导入的 AzureRM 模块。
- 尝试使用默认值模板配置云服务。 (如前所述,卡住了)
- 现在尝试通过从 powershell 传递参数来进行配置。 (效果很好)
- 现在使用默认值模板重试。 (效果很好)