Trouble Accessing Newly attached disk in DSC on an

2019-08-21 09:40发布

I have an issue with a DSC config i'm trying to use to install and run a mongo service on an Azure VM.

When the DSC runs on the initial deployment of the VM, the secondary disk 'F' is attached and formatted successfully, however... i receive an error when trying to create directories on the new disk:

Error message: \"DSC Configuration 'Main' completed with error(s).
Cannot find drive. A drive with the name 'F' does not exist. 
The PowerShell DSC resource '[Script]SetUpDataDisk' with SourceInfo 'C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\MongoDSC.0\\MongoDSC.ps1::51::2::Script' threw one or more non-terminating errors while running the Set-TargetResource functionality. 

Here is my DSC script :

Configuration Main
{

Param ( [string] $nodeName )

Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName xStorage

Node $nodeName
{
    xWaitforDisk Disk2
    {
        DiskId = 2
        RetryIntervalSec = 60
        RetryCount = 60
    }
    xDisk FVolume
    {
        DiskId = 2
        DriveLetter = 'F'
        FSLabel = 'MongoData'
        DependsOn = "[xWaitforDisk]Disk2"
    }
    Script SetUpDataDisk{
        TestScript ={
            return Test-Path "f:\mongoData\"
        }
        SetScript ={
            #set up the directories for mongo

            $retries = 0
            Do{
                $mountedDrive = Get-Volume | Where DriveLetter -eq 'F'
                if($mountedDrive -eq $null)
                {
                    Start-Sleep -Seconds 60
                    $retries = $retries + 1
                }
            }While(($mountedDrive -eq $null) -and ($retries -lt 60))

            $dirName = "mongoData"
            $dbDirName = "db"
            $logDirName = "logs"

            ##! ERROR THROWN FROM THESE LINES
            New-Item -Path "F:\$dirName" -ItemType Directory
            New-Item -Path "F:\$dirName\$dbDirName" -ItemType Directory
            New-Item -Path "F:\$dirName\$logDirName" -ItemType Directory
        }
        GetScript = {@{Result = "SetUpDataDisk"}}
        DependsOn = "[xDisk]FVolume"
    }
  }
}

The annoying thing is that if i run the deployment again everything works with no errors, i have put a loop in to try and wait for the disk to be ready but this still throws the error. I'm very new to DSC so any pointers would be helpful.

1条回答
太酷不给撩
2楼-- · 2019-08-21 10:23

It seems xDiskAccessPath can be used for that:

<#
    .EXAMPLE
        This configuration will wait for disk 2 to become available, and then make the disk available as
        two new formatted volumes mounted to folders c:\SQLData and c:\SQLLog, with c:\SQLLog using all
        available space after c:\SQLData has been created.
#>
Configuration Example
{

    Import-DSCResource -ModuleName xStorage

    Node localhost
    {
        xWaitforDisk Disk2
        {
             DiskId = 2
             RetryIntervalSec = 60
             RetryCount = 60
        }

        xDiskAccessPath DataVolume
        {
             DiskId = 2
             AccessPath = 'c:\SQLData'
             Size = 10GB
             FSLabel = 'SQLData1'
             DependsOn = '[xWaitForDisk]Disk2'
        }

        xDiskAccessPath LogVolume
        {
             DiskId = 2
             AccessPath = 'c:\SQLLog'
             FSLabel = 'SQLLog1'
             DependsOn = '[xDiskAccessPath]DataVolume'
        }
    }
}

https://github.com/PowerShell/xStorage/blob/dev/Modules/xStorage/Examples/Resources/xDiskAccessPath/1-xDiskAccessPath_InitializeDataDiskWithAccessPath.ps1

查看更多
登录 后发表回答