Powershell DSC 的Pull模式除了SMB以外,还可以使用HTTP或者HTTPS。这两个配置几乎一样,Https需要多配置一个证书。基本流程是配置pull server,配置节点的LCM,配置需要实现的状态,然后推送测试。
首先,我们需要一个web server的证书。我已经有PKI在域里了,因此从IIS生成一个证书非常容易。
具体步骤参考: http://beanxyz.blog.51cto.com/5570417/1331453
生成证书,绑定IIS之后,我需要获取该证书的指纹以便写入配置文件
和SMB一样,我需要下载导入模块
注意证书指纹的配置
configuration HTTPSPullServer { # Modules must exist on target pull server Import-DSCResource -ModuleName xPSDesiredStateConfiguration Node sydit01 { WindowsFeature DSCServiceFeature { Ensure = "Present" Name = "DSC-Service" } WindowsFeature IISConsole { Ensure = "Present" Name = "Web-Mgmt-Console" } xDscWebService PSDSCPullServer { Ensure = "Present" EndpointName = "PSDSCPullServer" Port = 8080 PhysicalPath = "$env:SystemDrive\inetpub\wwwroot\PSDSCPullServer" CertificateThumbPrint = ‘56B5DC192DE9AB004AE6FB3C96F7C00684537028‘ ModulePath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules" ConfigurationPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration" State = "Started" DependsOn = "[WindowsFeature]DSCServiceFeature" } xDscWebService PSDSCComplianceServer { Ensure = "Present" EndpointName = "PSDSCComplianceServer" Port = 9080 PhysicalPath = "$env:SystemDrive\inetpub\wwwroot\PSDSCComplianceServer" CertificateThumbPrint = "AllowUnencryptedTraffic" State = "Started" IsComplianceServer = $true DependsOn = ("[WindowsFeature]DSCServiceFeature","[xDSCWebService]PSDSCPullServer") } } } # Generate MOF HTTPSPullServer -OutputPath C:\DSC\HTTPS
生成Pull Server的配置文件
推送到指定的HTTPS服务器上
推送之后,需要测试一下是否成功
可以看见已经成功配置了
接下来需要配置节点的LCM文件
[DSCLocalConfigurationManager()] Configuration LCM_HTTPSPULL { param ( [Parameter(Mandatory=$true)] [string[]]$ComputerName, [Parameter(Mandatory=$true)] [string]$guid ) Node $ComputerName { Settings { AllowModuleOverwrite = $True ConfigurationMode = ‘ApplyAndAutoCorrect‘ RefreshMode = ‘Pull‘ ConfigurationID = $guid } ConfigurationRepositoryWeb DSCHTTPS { ServerURL = ‘https://sydit01.omnicom.com.au:8080/PSDSCPullServer.svc‘ CertificateID = ‘56B5DC192DE9AB004AE6FB3C96F7C00684537028‘ AllowUnsecureConnection = $False } } } # Computer list $ComputerName=‘sydittest‘ # Create Guid for the computers $guid=[guid]::NewGuid() # Create the Computer.Meta.Mof in folder LCM_HTTPSPULL -ComputerName $ComputerName -Guid $guid -OutputPath c:\DSC\HTTPS
生成LCM的meta.mof文件
推送给节点
接下来,配置我们需要实现的状态,这里的例子是确保SMTP服务始终不会安装。
configuration SMTP { Node HTTPSComputers { WindowsFeature SMTP{ Name = ‘SMTP-Server‘ Ensure = ‘Absent‘ } } } SMTP -OutputPath C:\DSC\HTTPS
生成mof文件
和SMB一样,HTTPS Pull Server 也是使用GUID和checksum来校验的,因此需要改名字,生成配置文件的校验码
最后来测试一下,首先看看客户端(节点)已经安装了SMTP
更新一下状态,发现他开始自动卸载
再查看一下,已经成功协助(提示需要重启)
实验成功。
本文出自 “麻婆豆腐” 博客,请务必保留此出处http://beanxyz.blog.51cto.com/5570417/1697842
Powershell DSC 5.0 - Pull 模式 (HTTPS)
原文:http://beanxyz.blog.51cto.com/5570417/1697842