DSC Push mode - best way to copy DSC resources

空扰寡人 提交于 2019-12-10 15:28:30

问题


I'm exploring DSC and wondering what's the best way to copy DSC resources to target host ?

When I try to push my configuration to the target host, It complain of missing DSC resource.

The PowerShell DSC resource xWebAdministration does not exist at the PowerShell module path nor is it registered as a WMI DSC resource.
    + CategoryInfo          : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : DscResourceNotFound
    + PSComputerName        : server1.appman.net

回答1:


The easiest way to ensure resources are available is to setup a file share based repository for pulling down modules. This blog should help you out http://nanalakshmanan.com/blog/Push-Config-Pull-Module/




回答2:


I tried to install PS modules using DSC. It requires 3 separate configurations:

Configuration InitialConfiguration
{
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'

    Node MyServer
    {
        Script InstallModule
        {
            SetScript = { Install-Module PackageManagement -MinimumVersion 1.1.7 -Force }
            TestScript = { $version = (Get-Module PackageManagement -ListAvailable).Version; $version.Major -ge 1 -and $version.Minor -ge 1 }
            GetScript = { Get-Module PackageManagement -ListAvailable }
        }
    }
}

Configuration ModulesConfiguration
{
    Import-DscResource -ModuleName 'PackageManagement' -ModuleVersion 1.1.7.0

    Node MyServer
    {
        PackageManagement xWebAdministration
        {
            Name = 'xWebAdministration'
        }
    }
}

Configuration WebServerConfiguration
{
    Import-DscResource –ModuleName 'xWebAdministration'

    Node MyServer
    {
        xWebAppPool SampleAppPool
        {
            Name = 'SampleAppPool'
        }
    }
}

However, Microsoft uses simple script to install modules using WinRM in their example.




回答3:


Create DSC configuration that will install modules, and modules can be taken from network share or more maybe may check out them from some repository like git but of course if they will have access to it. Push or pull whats better fit You.




回答4:


The error comes when module is not found in PSModule paths.
Use the following line to install xWebAdministration powershell module from PSGallery repository Install-Module -Name xWebAdministration

Then click "Yes to All" when a pop up comes, the module gets installed
To crosscheck if the module got installed, type $env:PSModulePath in powershell console and find xWebAdministration folder in PS Module paths




回答5:


# Commands for pushing DSC Resource Modules to Target Nodes.
# Resources you want to push must be available on this Authoring Machine.

#Required DSC resource modules
$moduleNames = "XWebAdministration", "xSMBShare", "cNtfsAccessControl", "OctopusDSC", "PSDSCResources", "DSCR_Font"

#ServerList to push files to
$Servers = "C:\temp\serverList.txt"
$serverList = (get-content $Servers |
    Where { $_ -notlike ";*" } | #lines that start with ';' will be considered comments
    ForEach { $_ } |
    select -Unique `
)

foreach ($server in $serverList)
{
    $Session = New-PSSession -ComputerName $server

    $getDSCResources = Invoke-Command -Session $Session -ScriptBlock {
        Get-DscResource
    }

    foreach ($module in $moduleNames)
    {
        if ($getDSCResources.moduleName -notcontains $module){
            #3. Copy module to remote node.
            $Module_params = @{
                Path = (Get-Module $module -ListAvailable).ModuleBase
                Destination = "$env:SystemDrive\Program Files\WindowsPowerShell\Modules\$module"
                ToSession = $Session
                Force = $true
                Recurse = $true
                Verbose = $true

            }

            Copy-Item @Module_params
        }
    }
    Remove-PSSession -Id $Session.Id
}


来源:https://stackoverflow.com/questions/36848209/dsc-push-mode-best-way-to-copy-dsc-resources

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!