Powershell

DSC 不拉配置

  • July 16, 2019

我的 DSC 節點沒有從我的 SMB DSC 伺服器中提取 DSC 配置。Get-DSCConfigurationStatus 表示拉取成功,但 Get-DSCConfiguration 保持不變(舊配置)。

我使用 HelloWorld 配置對其進行測試,其中在 C 驅動器上創建了一個文件。當我刪除文件 Get-DSCConfiguration 時顯示“Enusre:不存在”,但當它拉取新配置時,它應該是“確保:存在”。我沒有錯誤或其他任何東西。Idk 為什麼它沒有正確拉動。

我的 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 嗎?它有一個配置,並且節點試圖適應這個配置。所以它基本上必須再次拉取配置並應用它,而不是保留舊配置,拒絕拉取。但是舊的配置是錯誤的……我不明白……

它是配置模式,必須在 DSCLocalConfigurationManager 的設置下設置為 ApplyAndAutocorrect!

引用自:https://serverfault.com/questions/970337