在 Azure Stack Hub 中使用模板验证工具Use the template validation tool in Azure Stack Hub

使用模板验证工具检查 Azure 资源管理器模板是否已准备好部署到 Azure Stack Hub。Use the template validation tool to check whether your Azure Resource Manager templates are ready to deploy to Azure Stack Hub. 可从 Azure Stack Hub 工具 GitHub 存储库获取模板验证工具。The template validation tool is available in the Azure Stack Hub tools GitHub repo. 使用从 GitHub 下载工具中所述的步骤下载 Azure Stack Hub 工具。Download the Azure Stack Hub tools by using the steps described in Download tools from GitHub.

概述Overview

若要验证模板,必须先生成云功能文件,然后运行验证工具。To validate a template, you must first build a cloud capabilities file, and then run the validation tool. 通过 Azure Stack Hub 工具使用以下 PowerShell 模块:Use the following PowerShell modules from Azure Stack Hub tools:

  • azurerm.cloudcapabilities 文件夹中: hbase-runner.psm1 创建一个云功能 JSON 文件,用于表示 Azure Stack 中心云中的服务和版本。In the CloudCapabilities folder: Az.CloudCapabilities.psm1 creates a cloud capabilities JSON file representing the services and versions in an Azure Stack Hub cloud.
  • azurerm.templatevalidator.psm1 文件夹中: hbase-runner.psm1 使用云功能 JSON 文件在 Azure Stack Hub 中测试部署的模板。In the TemplateValidator folder: Az.TemplateValidator.psm1 uses a cloud capabilities JSON file to test templates for deployment in Azure Stack Hub.

生成云功能文件Build the cloud capabilities file

使用模板验证程序之前,请运行 Az. Azurerm.cloudcapabilities PowerShell 模块以生成 JSON 文件。Before you use the template validator, run the Az.CloudCapabilities PowerShell module to build a JSON file.

备注

如果更新集成系统,或添加任何新服务或虚拟扩展,应重新运行该模块。If you update your integrated system, or add any new services or virtual extensions, you should run this module again.

  1. 请确保已连接到 Azure Stack Hub。Make sure you have connectivity to Azure Stack Hub. 这些步骤可从 Azure Stack 开发工具包 (ASDK) 主机执行,也可以使用 VPN 从工作站连接。These steps can be done from the Azure Stack Development Kit (ASDK) host, or you can use a VPN to connect from your workstation.

  2. 导入 Azurerm.cloudcapabilities PowerShell 模块:Import the Az.CloudCapabilities PowerShell module:

    Import-Module .\CloudCapabilities\Az.CloudCapabilities.psm1
    
  3. 使用 Get-CloudCapabilities cmdlet 检索服务版本,并创建云功能 JSON 文件。Use the Get-CloudCapabilities cmdlet to retrieve service versions and create a cloud capabilities JSON file. 如果未指定 -OutputPath,则将在当前目录中创建文件 AzureCloudCapabilities.jsonIf you do not specify -OutputPath, the file AzureCloudCapabilities.json is created in the current directory. 使用你的实际 Azure 位置:Use your actual Azure location:

Get-AzCloudCapability -Location <your location> -Verbose

验证模板Validate templates

使用以下步骤可通过使用 Azurerm.templatevalidator.psm1 PowerShell 模块来验证模板。Use these steps to validate templates by using the Az.TemplateValidator PowerShell module. 可以使用自己的模板,或使用 Azure Stack Hub 快速入门模板You can use your own templates, or use the Azure Stack Hub Quickstart templates.

  1. 导入 azurerm.templatevalidator.psm1. Hbase-runner.psm1 PowerShell 模块:Import the Az.TemplateValidator.psm1 PowerShell module:

    cd "c:\AzureStack-Tools-az\TemplateValidator"
    Import-Module .\Az.TemplateValidator.psm1
    
  2. 运行模板验证程序:Run the template validator:

Test-AzTemplate -TemplatePath <path to template.json or template folder> `
-CapabilitiesPath <path to cloudcapabilities.json> `
-Verbose

模板验证警告或错误会显示在 PowerShell 控制台中并写入到源目录中的一个 HTML 文件中。Template validation warnings or errors are displayed in the PowerShell console and written to an HTML file in the source directory. 以下屏幕截图是验证报告的一个示例:The following screenshot is an example of a validation report:

模板验证报告

parametersParameters

模板验证程序 cmdlet 支持以下参数。The template validator cmdlet supports the following parameters.

参数Parameter 描述Description 必须Required
TemplatePath 指定要在其中递归查找 Azure 资源管理器模板的路径。Specifies the path to recursively find Azure Resource Manager templates. Yes
TemplatePattern 指定要匹配的模板文件的名称。Specifies the name of template files to match. No
CapabilitiesPath 指定云功能 JSON 文件的路径。Specifies the path to the cloud capabilities JSON file. Yes
IncludeComputeCapabilities 包括 IaaS 资源(例如 VM 大小和 VM 扩展)的评估。Includes evaluation of IaaS resources, such as VM sizes and VM extensions. No
IncludeStorageCapabilities 包括存储资源(例如 SKU 类型)的评估。Includes evaluation of storage resources, such as SKU types. No
Report 指定生成的 HTML 报告的名称。Specifies the name of the generated HTML report. No
Verbose 将错误和警告记录到控制台。Logs errors and warnings to the console. No

示例Examples

此示例验证下载到本地存储的所有 Azure Stack Hub 快速入门模板This example validates all of the Azure Stack Hub Quickstart templates downloaded to local storage. 该示例还根据 ASDK 功能验证虚拟机 (VM) 大小和扩展。The example also validates virtual machine (VM) sizes and extensions against ASDK capabilities.

test-AzTemplate -TemplatePath C:\AzureStack-Quickstart-Templates `
-CapabilitiesPath .\TemplateValidator\AzureStackCloudCapabilities_with_AddOns_20170627.json `
-TemplatePattern MyStandardTemplateName.json `
-IncludeComputeCapabilities `
-Report TemplateReport.html

后续步骤Next steps