具有 DSC 扩展名的 ARM 模板:来自本地桌面的 Powershell 文件位置

ARM Template with DSC extension: Powershell file location from local destop

我想将包含 DSC 相关 PS 脚本的 ARM 模板项目发送给第三方。他们可能会在 VS 中部署选项来进行部署。可以将 DSC 脚本附加为 ARM 项目的一部分,并在部署时从本地磁盘获取 dsc 脚本吗?在设置下,我们有 "ModulesUrl" 可以用另一个指向本地磁盘的参数替换它,例如 c:\myproject\IISInstall.ps1.zip

{
  "apiVersion": "2015-06-15",
  "dependsOn": [
    "[concat('Microsoft.Compute/virtualMachines/', parameters('webSrvVmName'))]"
  ],
  "location": "[resourceGroup().location]",
  "name": "qawebsrv/iisinstall",
  "properties": {
    "publisher": "Microsoft.Powershell",
    "type": "DSC",
    "typeHandlerVersion": "2.19",
    "autoUpgradeMinorVersion": true,
    "settings": {
      "ModulesUrl": "https://dscscript.blob.core.windows.net/dscscripts/IISInstall.ps1.zip",
      "ConfigurationFunction": "[variables('configurationFunction')]",
      "Properties": {},
      "SasToken": "",
      "wmfVersion": "4.0"
    },
    "protectedSettings": {}
  },
  "tags": {
    "displayName": "VM Extensions"
  },
  "type": "Microsoft.Compute/virtualMachines/extensions"
}

不,这是不可能的。最接近的方法是将您的脚本上传到一个公开可用的位置,VM 将拉取它。

"properties": {
    "publisher": "Microsoft.Powershell",
    "type": "DSC",
    "typeHandlerVersion": "2.20",
    "autoUpgradeMinorVersion": true,
    "settings": {
        "configuration": {
            "url": "https://github.com/xxx.zip",
            "script": "scriptname.ps1",
            "function": "main"
        },
        "configurationArguments": {}
    },
    "protectedSettings": {}
}

如果您打算使用 VS 进行部署,那么 VS 可以为您暂存 DSC 包 - VS 中的部署脚本可以执行此操作...它实际上也可以构建 DSC 包,但是有一些限制。

VS 脚本没有什么神奇之处 - 这个 repo 有一个 DSC 示例,它使用 VS 使用的相同脚本 - 请参阅:https://github.com/bmoore-msft/AzureRM-Samples/tree/master/VMDSCInstallFile

举个 "Hello World" 例子...