Azure ARM 模板和 PowerShell 模块

Azure ARM Template and PowerShell Module

我在 PowerShell 库上发布了一个模块,我想使用 Azure ARM 模板部署该模块。而且我没找到怎么办!

这是我的模板:

   "resources": [
  {
     "name": "[variables('automationAccountName')]",
     "type": "Microsoft.Automation/automationAccounts",
     "apiVersion": "2015-10-31",
     "location": "[parameters('AutomationLocation')]",
     "tags": {
        "displayName": "Compte Automation"
     },
     "properties": {
        "sku": {
           "name": "Basic",
           "family": "B"
        }
     },
     "resources": [
        {
           "name": "[variables('powerShellGalleryModuleName')]",
           "type": "modules",
           "apiVersion": "2015-10-31",
           "location": "[parameters('AutomationLocation')]",
           "properties": {
              "isGlobal": false,
              "sizeInBytes": 0,
              "contentLink": {
                    "uri": "[variables('powerShellGalleryModule')]"
              }
           }
        }
     ]
  }
]

应该为变量提供什么 powerShellGalleryModule?

我们可以使用以下任一方法将这些集成模块导入到 Azure 自动化中:

1.Using New-AzureRmAutomationModule AzureRm.Automation 模块中的 cmdlet。
2.Using Azure 门户 并导航到自动化帐户中的资产。
3.Using Azure 资源管理器 (ARM) 模板

我们可以使用 ARM 模板来部署我们的自定义集成模块。这是一个示例模板:

"$schema": "http://schemas.microsoft.org/azure/deploymentTemplate?api-version=2015-01-01-preview#",
      "contentVersion": "1.0",
      "parameters": {
        "automationAccountType": {
          "type": "string",
          "allowedValues": [
            "New",
            "Existing"
          ]
        },
        "automationAccountName": {
          "type": "string"
        },
        "moduleName": {
          "type": "string"
        },
        "moduleUri":{
          "type": "string"  
        }
      },
      "variables": {
        "templatelink": "[concat('https://devopsgallerystorage.blob.core.windows.net/azureautomationpackages/templates%5Corigtemplates%5C', parameters('automationAccountType'), 'AccountTemplate.json')]"
      },
      "resources": [
        {
          "apiVersion": "2015-01-01",
          "name": "nestedTemplate",
          "type": "Microsoft.Resources/deployments",
          "properties": {
            "mode": "incremental",
            "templateLink": {
              "uri": "[variables('templatelink')]",
              "contentVersion": "1.0"
            },
            "parameters": {
              "accountName": {
                "value": "[parameters('automationAccountName')]"
              },
              "accountLocation": {
                "value": "[resourceGroup().Location]"
              },
              "moduleName": {
                "value": "[parameters('moduleName')]"
              },
              "moduleUri": {
                "value": "[parameters('moduleUri')]"
              }
            }
          }
        }
      ]
    }

有关使用 ARM 模板部署自定义 Azure 自动化集成模块的更多信息,请参阅 Ravikanth 撰写的link

我找到了通过 PowerShellGallery 完成的方法

这样:

            {
           "name": "[variables('powerShellGalleryModule')]",
           "type": "modules",
           "apiVersion": "2015-10-31",
           "location": "[parameters('AutomationLocation')]",
           "properties": {
              "isGlobal": false,
              "sizeInBytes": 0,
              "contentLink": {
                 "uri": "[concat('https://www.powershellgallery.com/api/v2/package/', variables('powerShellGalleryModule'))]"
              }
           },
           "dependsOn": [
              "[resourceId('Microsoft.Automation/automationAccounts', variables('automationAccountName'))]"
           ]
        },