dsccommunity / SqlServerDsc

This module contains DSC resources for deployment and configuration of Microsoft SQL Server.
MIT License
359 stars 224 forks source link

Install Name Instance Failover Cluster First Node - #1040

Closed kiransqldba closed 6 years ago

kiransqldba commented 6 years ago

Configuration Clust_node1 { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [ValidateNotNullorEmpty()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $SqlInstallCredential,

    [Parameter()]
    [ValidateNotNullorEmpty()]
    [System.Management.Automation.PSCredential]
    [System.Management.Automation.Credential()]
    $SqlAdministratorCredential = $SqlInstallCredential

)
      Import-DscResource -ModuleName SqlServerDsc

node localhost
{
    #region Install prerequisites for SQL Server
    WindowsFeature 'NetFramework35'
    {
        Name   = 'NET-Framework-Core'
        Source = 'C:\SQLInstall\WinSev2016Evalution\Sources\Sxs' # Assumes built-in Everyone has read permission to the share and path.
        Ensure = 'Present'
    }

    WindowsFeature 'NetFramework45'
    {
        Name   = 'NET-Framework-45-Core'
        Ensure = 'Present'
    }
    #endregion Install prerequisites for SQL Server

    #region Install SQL Server Failover Cluster
    SqlSetup 'InstallNamedInstanceNode1-INST2016'
    {
        Action                     = 'InstallFailoverCluster'
        ForceReboot                = $false
        UpdateEnabled              = 'False'
        SourcePath                 = 'C:\SQLInstall\SQLBinaries'
        SourceCredential           = $SqlInstallCredential

        InstanceName               = 'INST2017'
        Features                   = 'SQLENGINE'

        InstallSharedDir           = 'C:\Program Files\Microsoft SQL Server'
        InstallSharedWOWDir        = 'C:\Program Files (x86)\Microsoft SQL Server'
        InstanceDir                = 'C:\Program Files\Microsoft SQL Server'

        SQLCollation               = 'Finnish_Swedish_CI_AS'
        SQLSvcAccount              = 'TestDomain\sqlengine'
        AgtSvcAccount              = 'TestDomain\sqlagent'
        SQLSysAdminAccounts        = 'TestDomain\k_dba', $SqlAdministratorCredential.UserName

        # Drive D: must be a shared disk.
        InstallSQLDataDir          = 'E:\MSSQL\Data'
        SQLUserDBDir               = 'E:\MSSQL\Data'
        SQLUserDBLogDir            = 'F:\MSSQL\Log'
        SQLTempDBDir               = 'H:\MSSQL\Temp'
        SQLTempDBLogDir            = 'H:\MSSQL\Temp'
        SQLBackupDir               = 'H:\MSSQL\Backup'
        FailoverClusterNetworkName = 'SQLCLUS01'
        FailoverClusterIPAddress   = '172.16.0.xxx'
        FailoverClusterGroupName   = 'WINCLUS'

        PsDscRunAsCredential       = $SqlInstallCredential

        DependsOn                  = '[WindowsFeature]NetFramework35', '[WindowsFeature]NetFramework45'
    }

    #region Install SQL Server Failover Cluster
}

} $cd = @{ AllNodes = @( @{ NodeName = 'localhost' PSDscAllowDomainUser = $true

PSDscAllowPlainTextPassword = $true

        CertificateFile = "C:\SQLInstall\server1.cer"
    }
)

}

$cred = Get-Credential -UserName 'KPAD2018\Administrator' -Message "Password please"

Clust_node1 -DomainCredential $cred -ConfigurationData $cd

I used above example from Example Resource and tried to install SQL Cluster on Node1 but getting below error

**ConvertTo-MOFInstance : System.InvalidOperationException error processing property 'SourceCredential' OF TYPE 'SqlSetup': Converting and storing encrypted passwords as plain text is not recommended. For more information on securing credentials in MOF file, please refer to MSDN blog: http://go.microsoft.com/fwlink/?LinkId=393729 At C:\SQLInstall\SQL_Cluster_Installation\Clust_Config1.ps1:72 char:9

I have passed value for PSDscAllowDomainUser even though it's throwing error, Anyone knows what wrong in code.

Thanks in Advance.

randomnote1 commented 6 years ago

If you're going to allow a plain text password to be stored, you need to uncomment PSDscAllowPlainTextPassword = $true. Otherwise you'll need to specify a certificate to use for encryption.

kiransqldba commented 6 years ago

Hello Dan,

I have tried that too even though getting same error.

randomnote1 commented 6 years ago

I made a few tweaks and was able to get the configuration to compile on my machine. I commented the lines where I made a change. I think the biggest issue was the SQLSvcAccount and SQLSvcAccount parameters require a credential object, not just the username.

Configuration Clust_node1
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $SqlInstallCredential,

        [Parameter()]
        [ValidateNotNullorEmpty()]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $SqlAdministratorCredential = $SqlInstallCredential

    )
    Import-DscResource -ModuleName SqlServerDsc

    node localhost
    {
        #region Install prerequisites for SQL Server
        WindowsFeature 'NetFramework35' {
            Name   = 'NET-Framework-Core'
            Source = 'C:\SQLInstall\WinSev2016Evalution\Sources\Sxs' # Assumes built-in Everyone has read permission to the share and path.
            Ensure = 'Present'
        }

        WindowsFeature 'NetFramework45' {
            Name   = 'NET-Framework-45-Core'
            Ensure = 'Present'
        }
        #endregion Install prerequisites for SQL Server

        #region Install SQL Server Failover Cluster
        SqlSetup 'InstallNamedInstanceNode1-INST2016'
        {
            Action                     = 'InstallFailoverCluster'
            ForceReboot                = $false
            UpdateEnabled              = 'False'
            SourcePath                 = 'C:\SQLInstall\SQLBinaries'
            SourceCredential           = $SqlInstallCredential

            InstanceName               = 'INST2017'
            Features                   = 'SQLENGINE'

            InstallSharedDir           = 'C:\Program Files\Microsoft SQL Server'
            InstallSharedWOWDir        = 'C:\Program Files (x86)\Microsoft SQL Server'
            InstanceDir                = 'C:\Program Files\Microsoft SQL Server'

            SQLCollation               = 'Finnish_Swedish_CI_AS'

            #### This needs to be a credential object
            SQLSvcAccount              = $SqlInstallCredential

            #### This needs to be a credential object
            AgtSvcAccount              = $SqlInstallCredential
            SQLSysAdminAccounts        = 'TestDomain\k_dba', $SqlAdministratorCredential.UserName

            # Drive D: must be a shared disk.
            InstallSQLDataDir          = 'E:\MSSQL\Data'
            SQLUserDBDir               = 'E:\MSSQL\Data'
            SQLUserDBLogDir            = 'F:\MSSQL\Log'
            SQLTempDBDir               = 'H:\MSSQL\Temp'
            SQLTempDBLogDir            = 'H:\MSSQL\Temp'
            SQLBackupDir               = 'H:\MSSQL\Backup'
            FailoverClusterNetworkName = 'SQLCLUS01'
            FailoverClusterIPAddress   = '172.16.0.xxx'
            FailoverClusterGroupName   = 'WINCLUS'

            PsDscRunAsCredential       = $SqlInstallCredential

            DependsOn                  = '[WindowsFeature]NetFramework35', '[WindowsFeature]NetFramework45'
        }

        #region Install SQL Server Failover Cluster
    }
}

$cd = @{
    AllNodes = @(
        @{
            NodeName             = 'localhost'
            PSDscAllowDomainUser = $true
            PSDscAllowPlainTextPassword = $true

            #### Got rid of the certificate for the time being
            #CertificateFile      = "C:\SQLInstall\server1.cer"
        }
    )
}

$cred = Get-Credential -UserName 'KPAD2018\Administrator' -Message "Password please"

Clust_node1 -SqlInstallCredential $cred -ConfigurationData $cd
kiransqldba commented 6 years ago

Thank you very much Dan. It's working. Let me try to install cluster now.

randomnote1 commented 6 years ago

Awesome! Glad it's working 😃

kiransqldba commented 6 years ago

Hello Dan,

I was excited too early, but I knew it's just MOF file :). Real issue comes when I will install SQL Cluster and that what it happen

**Error The network name cannot be found.

No MSFT_SmbMapping objects found with property 'RemotePath' equal to 'C:\SQLInstall\SQLBinaries\'. Verify the value of the property and retry.

The PowerShell DSC resource '[SqlSetup]InstallNamedInstanceNode1-INST2016' with SourceInfo 'C:\SQLInstall\SQL_Cluster_Installation\Cluster_node2.ps1::37::9::SqlSetup' threw one or more non-terminating errors while running the Test-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.

The SendConfigurationApply function did not succeed.

randomnote1 commented 6 years ago

I believe what is happening is that the resource is expecting the SourcePath to be a UNC path (e.g. \\server\path\to\media) because the SourceCredential parameter is set. If the installation media is sitting on a share, ensure you have the share path in the SourcePath parameter. Otherwise, I think getting rid of the SourceCredential parameter will work.

kiransqldba commented 6 years ago

Thanks Dan. It's working but got another error.

I have manually installed SQL Cluster and working fine and verified all the Cluster Configuration and Disk as well so don't understand why it's throwing error for disk 3 and disk 4. Is that something do I have mentioned specifically in the configuration file?

PowerShell DSC resource MSFT_SqlSetup failed to execute Set-TargetResource functionality with error message: System.Exception: Unable to map the specified paths to valid cluster storage. Drives mapped: Cluster Disk 3; Cluster Disk 4.

The SendConfigurationApply function did not succeed.

randomnote1 commented 6 years ago

Hmm, that's not a lot of information in that error message. I think the whatever disks Cluster Disk 3 and 4 are are not usable as cluster storage. However, you will probably need to dig into the cluster log to find out. Get-ClusterLog should be of use to you here.

kiransqldba commented 6 years ago

I dig into Bootstrap logs and found below error,

Exception type: Microsoft.SqlServer.Chainer.Infrastructure.InputSettingValidationException Message: The IP address '172.16.0.171' has network name 'Production_DC2', which is not supported locally. HResult : 0x84b40002 FacilityCode : 1204 (4b4) ErrorCode : 2 (0002)

After I re-tried couple of times with different settings but nothing worked out.

and again installed manually with GUI and successfully installed without any error.

Do you have any idea about error?

stale[bot] commented 6 years ago

This issue has been automatically marked as needs more information because it has not had activity from the community in the last 30 days. It will be closed if no further activity occurs within 10 days. If the issue is label with any of the work labels (e.g bug, enhancement, documentation, or tests) the issue will not auto-close.

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had activity from the community in the last 30 days. It will be closed if no further activity occurs within 10 days. If the issue is labelled with any of the work labels (e.g bug, enhancement, documentation, or tests) then the issue will not auto-close.

stale[bot] commented 6 years ago

This issue has been automatically closed because it is has not had activity from the community in the last 40 days.