我的 DSC 节点未从我的 SMB DSC 服务器提取 DSC 配置。Get-DSCConfigurationStatus 表示提取成功,但 Get-DSCConfiguration 保持不变(旧配置)。
我正在使用 HelloWorld 配置对其进行测试,其中在 C 盘上创建了一个文件。当我删除文件时,Get-DSCConfiguration 显示“Enusre: Absent”,但当它提取新配置时,它应该是“ensure: present”。我没有遇到任何错误或其他问题。我不知道为什么它提取不正确。
我的DSC LCM配置:
$secpasswd = ConvertTo-SecureString “PASSWORD” -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential (“SERVUSER”, $secpasswd)
[DSCLocalConfigurationManager()]
configuration PullClientConfig
{
param(
[PSCredential]$DomainCredential
)
Node 'localhost'
{
Settings
{
RefreshMode = 'Pull'
RefreshFrequencyMins = 30
RebootNodeIfNeeded = $false
ConfigurationID = '2fda9b6d-e1be-46a9-8b92-e25cb17026cd'
}
ConfigurationRepositoryShare SmbConfigShare
{
SourcePath = '\\SERVER\SHARE'
Credential = $mycreds
}
ResourceRepositoryShare SmbResourceShare
{
SourcePath = '\\SERVER\SHARE'
Credential = $mycreds
}
}
}
$cd = @{
AllNodes = @(
@{
NodeName = 'localhost'
PSDscAllowPlainTextPassword = $true
}
)
}
我的 HelloWord 配置:
Configuration HelloWorld {
param (
[string[]]$ComputerName = "localhost" # i have changed this parameter to the servername
)
# Import the module that contains the File resource.
Import-DscResource -ModuleName PsDesiredStateConfiguration
# The Node statement specifies which targets to compile MOF files for, when this configuration is executed.
Node $ComputerName {
# The File resource can ensure the state of files, or copy them from a source to a destination with persistent updates.
File HelloWorld {
DestinationPath = "C:\HelloWorld.txt"
Ensure = "Present"
Contents = "Hello World from DSC!"
}
}
}
Update-DScConfiguration 表示没有更新的配置,因此不会拉取。我理解 DSC 是否正确,它有一个配置,节点会尝试适应此配置。因此它基本上必须再次拉取配置并应用它,相反,它会保留旧配置,拒绝拉取。但旧配置是错误的......我不明白......
答案1
它是 ConfigurationMode,必须在 DSCLocalConfigurationManager 中的“设置”下将其设置为 ApplyAndAutocorrect!