【问题标题】:Trouble Accessing Newly attached disk in DSC on an azure VM在 Azure VM 上的 DSC 中访问新连接的磁盘时遇到问题
【发布时间】:2018-01-24 19:54:53
【问题描述】:

我尝试使用 DSC 配置在 Azure VM 上安装和运行 mongo 服务时遇到问题。

当 DSC 在 VM 的初始部署上运行时,辅助磁盘“F”已成功附加并格式化,但是...尝试在新磁盘上创建目录时收到错误消息:

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. 

这是我的 DSC 脚本:

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"
    }
  }
}

烦人的事情是,如果我再次运行部署,一切正常,没有错误,我已经放入一个循环来尝试等待磁盘准备好,但这仍然会引发错误。我对 DSC 很陌生,所以任何指针都会有所帮助。

【问题讨论】:

标签: azure virtual-machine dsc


【解决方案1】:

似乎 xDiskAccessPath 可以用于此:

<#
    .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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-27
    • 2020-06-12
    • 2022-06-15
    • 1970-01-01
    • 2018-10-23
    • 2018-02-28
    • 2021-01-19
    • 1970-01-01
    相关资源
    最近更新 更多