如何在使用Azure自动化时将参数传递给Azure DSC扩展?

时间:2018-02-12 19:06:22

标签: azure-resource-manager dsc

根据(https://docs.microsoft.com/en-us/azure/virtual-machines/windows/extensions-dsc-template#default-configuration-script),如果使用默认配置脚本,则无法传递参数。那么如何同时使用Azure Automation入门并将参数传递给DSC脚本呢?这两者似乎都不可能。

  "resources": [
    {
      "name": "Microsoft.Powershell.DSC",
      "type": "extensions",
      "location": "[resourceGroup().location]",
      "apiVersion": "2015-06-15",
      "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', parameters('swarmmanager1Name'))]"
      ],
      "tags": {
        "displayName": "DSC"
      },
      "properties": {
        "publisher": "Microsoft.Powershell",
        "typeHandlerVersion": "2.26",
        "type":  "DSC",
        "autoUpgradeMinorVersion": true,
        //"forceUpdateTag": "[parameters('DSCExtensionManagerTagVersion')]",
        "settings": {
          "wmfVersion": "latest",
          "configurationArguments": {
            "RegistrationKey": {
              "UserName": "PLACEHOLDER_DONOTUSE",
              "Password": "[parameters('RegistrationKey')]"
            },
            "CustomData" :  "hello from ARM",
            "RegistrationUrl": "[parameters('registrationUrl')]",
            "NodeConfigurationName": "SwarmManager.localhost",
            "RebootNodeIfNeeded": true
          }
        }
      }
    }
      ]
    },

DSC配置

Configuration SwarmManager
{
    param
    (
[string] $CustomData
    )

    Import-DscResource -ModuleName PSDesiredStateConfiguration
    Import-DscResource -ModuleName PackageManagement -ModuleVersion "1.1.7.0"

    Node localhost
    {

        PackageManagement xPSDesiredStateConfiguration {
            Ensure = 'present'
            Name   = "xPSDesiredStateConfiguration"
            Source = "PSGallery"

        } 

        File DumpParameters {
            Destinationpath = "c:\out.txt"
            Contents = "Hello $CustomData"
        }
    }
}

收到错误

The DSC Extension received an incorrect input: A parameter cannot be found that matches parameter name 'CustomData'

0 个答案:

没有答案