我目前正在build立一个实验室环境,以了解DSC可以完成什么以及在哪些限制范围内。
我们需要根据操作系统,AD组成员和包含目标的OU等标准推出一次性configuration到一组节点。
所以我开发了以下示例脚本:
# Pulls computer objects from Active Directory Function Get-Nodes { Param($OperatingSystem) Get-AdComputer -Filter 'OperatingSystem -eq ${OperatingSystem}' -SearchBase "OU=SomeThing,DC=contoso,DC=com" } # Defines the configuration to apply Configuration ConfigureHostsPush { Node $Allnodes.NodeName { # This resource is not able to delete a key, only values Registry ConfigureRegistry { Ensure = "Present" Key = "HKEY_LOCAL_MACHINE\SOFTWARE\" ValueName = "MachineType" ValueData = "Hyper-V" } # This logs the defined message at the _destination_ host # within Microsoft->Windows->DesiredStateConfiguration->Analytic # requires showing and enabling the log first! Log LogSuccessfulRegistry { Message = "Successfully configued the defined registry value" DependsOn = "[Registry]ConfigureRegistry" } } } $nodes = Get-Nodes -OperatingSystem "Windows Server 2012 R2 Standard" # $nodes = Get-Nodes -OperatingSystem "Windows Server 2008 R2 Standard" # $nodes = Get-Nodes -OperatingSystem "Windows 7 Professional" # Pulls a list of nodes into a hash table $ConfigData = @{ AllNodes = @( foreach ($node in $nodes) { @{NodeName = $node.Name} } ) } # Generate the MOFs based on the configuration and hosts pulled from AD ConfigureHostsPush -ConfigurationData $ConfigData # Actually push out the configuration to the nodes Start-DscConfiguration -wait -Path D:\DATA\DSC\ConfigureHostsPush
但是,有些节点并不总是可及的,在我的情况下是离线的。 我应该怎么做error handling和日志? 所以我稍后可以控制哪些节点成功configuration或需要重新configuration。
我知道我可以使用DSC日志资源,但似乎相当有限,只能在LCM /目标节点端生成日志。
一种方法是只是不跟踪。 只需将所有mof文件放在一个文件夹中,并让计划任务每天运行两次,将其推送到您的节点。 这将很容易build立和pipe理。 设置它,忘记它。
预期的用例是build立一个拉服务器。 您仍然必须configuration每个节点与拉服务器交谈。 由于节点必须使用拉取服务器进行检入,所以您确实有一个中央位置,告诉您节点是否已检入并正确configuration。 您还可以更改拉服务器上的configuration,节点将在下次检入时得到它。 你不必照顾推送过程。
在开始尝试configuration所有现有服务器时,您将面临最大的问题。 但是今后,部署一个新的服务器将处于一个您可以在configuration过程中密切pipe理的状态。