无法在所需状态配置中运行节点和脚本

时间:2017-03-28 13:21:16

标签: powershell azure dsc azure-resource-manager

背景

我使用ARM模板在Azure中配置VM,并创建了一个安装和配置IIS的Desired State Configuration .ps1文件。到目前为止一切都很好。

然后我在Script块旁边添加了Node块。

当前设置:

Configuration Main
{
    Param ( [string] $nodeName )

    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node $nodeName
    {
        WindowsFeature WebServer
        {
            Name = "Web-Server"
            Ensure = "Present"
        }

        #other WindowsFeatures
    }

    Script FormatDiskScript
    {
        SetScript =
        {
            #Powershell to format disks
        }
        TestScript = { return $false }
        GetScript = { }
    }
}

在我的ARM模板中,我已将DSC扩展添加到我的VM并指定url从哪里获取zip文件,script运行并function调用。

"properties": {
  "publisher": "Microsoft.Powershell",
  "type": "DSC",
  "typeHandlerVersion": "2.23",
  "autoUpgradeMinorVersion": true,
  "settings": {
    "configuration": {
      "url": "[concat(parameters('_artifactsLocation'), '/', variables('dscArchiveFolder'), '/', variables('webvm_dscZipFileName'))]",
      "script": "webvm-dsc.ps1",
      "function": "Main"
    },
    "configurationArguments": {
      "nodeName": "[variables('webvm_name')]"
    }
  },
  "protectedSettings": {
    "configurationUrlSasToken": "[parameters('_artifactsLocationSasToken')]"
  }
}

问题

它生成两个.mof文件并执行NodeScript部分,但只有Node部分成功完成。

当我只使用Script运行时,这是有效的,因此Script有效。我只是在运行它们时遇到问题。

这是我在C:\ Packages \ Plugins \ Microsoft.Powershell.DSC \ 2.23.0.0 \ Status \ 0.status

的输出中看到的
Settings handler status to 'transitioning' 
Updating execution status 
DSC configuration completed
No meta mof back up file exist to restore ...
Settings handler status to 'error' 

答案

在尝试了不同的方法之后,我终于偶然发现了一个有效的方法。我只是将Script放在Node内而不是同伴:

Configuration Main
{
    Param ( [string] $nodeName )

    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node $nodeName
    {
        WindowsFeature WebServer
        {
            Name = "Web-Server"
            Ensure = "Present"
        }

        #other WindowsFeatures

        Script FormatDiskScript
        {
             SetScript =
             {
                 #Powershell to format disks
             }
             TestScript = { return $false }
             GetScript = { }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

你需要在DSC配置中创建2个配置(比如主要和手动)并将你想要用ARM模板执行的东西放到main中,把另一个放到手册中

或者在2个单独的文件中创建2个单独的配置。