Skip to content

Commit 18bca74

Browse files
authored
Merge pull request #5 from virtualdesktopdevops/dev
Release v2.0.0-PuppetForge
2 parents e3ad520 + 401a154 commit 18bca74

16 files changed

+236
-256
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pkg/

.pmtignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pkg/
2+
tests/
3+
assets/
4+
_config.yml
5+
.fixtures.yml

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Changelog - sqlserveralwayson #
2+
3+
## Version 2.0.0
4+
- **BREAKING CHANGE** : Require puppetlabs/dsc compiled with SQLServerDSC >= 10.0.0.0
5+
- **BREAKING CHANGE** : Changed $sqlservicecredential_username and $sqlagentservicecredential_username format. User accounts now required **WITHOUT** Netbios Domain Name prefix.
6+
- **BREAKING CHANGE** : Removed $domainName class parameter. Used facts instead.
7+
- **BREAKING CHANGE** : Removed $domainNetbiosName class parameter. Used custom fact instead.
8+
- Changed database availability mode to SynchronousCommit
9+
10+
11+
## Version 1.1.0
12+
- Module compatible with xSQLServer <= 9.0.0.0
13+
14+
## Version 1.0.0
15+
- Initial release

README.markdown

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# sqlserveralwayson #
22

3-
This modules install a fully working SQL Server AlwaysOn cluster. It has been designed to install both primary replica nodes with the following features :
3+
This modules installs a fully working Microsoft SQL Server AlwaysOn cluster. It has been designed to install both primary replica nodes with the following features :
44
- SPN creation on sql service account (service account not yet created by this module, schedulded in next release)
55
- SQL server installation and initial configuration (MaxDop Firewall, Memory, Admin rights, ...)
66
- Failover cluster creation (primary node) or join (replica node) with File Share witness
@@ -12,17 +12,19 @@ The default MSSQLSERVER SQL Server instance is created during installation. This
1212

1313
The database failover mecanism integrated in this module is SQL Server AlwaysOn.
1414

15-
The module can be installed on a Standard, Datacenter, or Core version of Windows 2012R2 or Windows 2016.
15+
The module can be installed on a Standard, Datacenter, Core version of Windows 2012R2 or Windows 2016.
16+
17+
**BREAKING CHANGE :** This module requires puppetlabs/dsc compiled with SQLServerDSC >= 10.0.0.0
1618

1719
## Usage
1820
- **setup_svc_username** : (string) Privileged account used by Puppet for installing the software and creating the failover cluster (spn creation, computer registration, local administrator privilèges needed)
1921
- **setup_svc_password** : (string) Password of the privileged account. Should be encrypted with hiera-eyaml.
2022
- **setupdir** : (string) Path of a folder containing the SQL Server installer (unarchive the ISO image in this folder).
2123
- **sa_password** : (string) SQL Server SA password for mixed mode SQL authentication configuration.
2224
- **productkey** : (string)(optionnal) Product key for licensed installations.
23-
- **sqlservicecredential_username** : (String) Service account for the SQL service
25+
- **sqlservicecredential_username** : (String) Domain service account for the SQL service **WITHOUT** Netbios Domain Name prefix. The account will be automatically created in Active Directory by the module. MSSQLSvc/fqdn_of_sql_server_node SPN will be associated with the service account.
2426
- **sqlservicecredential_password** : (String) : Password of the service account for the SQL service. Should be encrypted with hiera-eyaml.
25-
- **sqlagentservicecredential_username** : (String) Service account for the SQL Agent service
27+
- **sqlagentservicecredential_username** : (String) Domain service account for the SQL Agent service **WITHOUT** Netbios Domain Name prefix. The account will be automatically created in Active Directory by the module.
2628
- **sqlagentservicecredential_password** : (String) Password of the service account for the SQL Agent service. Should be encrypted with hiera-eyaml.
2729
- **sqladministratoraccounts** : (String[] Array) : Array of accounts to be made SQL administrators.
2830
- **sqluserdbdir** : (String)(optionnal) Path for SQL database files. Default to 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Data'
@@ -35,7 +37,6 @@ The module can be installed on a Standard, Datacenter, or Core version of Window
3537
- **fileShareWitness** : (String) Fileshare witness UNC path in the format'\\witness.company.local\witness$'. Needs to be writable by SQL nodes.
3638
- **listenerIP** : (String) The IP address used for the availability group listener, in the format 192.168.10.45/255.255.252.0.
3739
- **role** : (String) Needs to be 'primary' for primary SQL nodes or 'secondary' for SQL replica nodes
38-
- **domainNetbiosName** : (String) Active Directory domain NETBIOS name
3940

4041

4142
## Installing a Microsoft SQL Server AlwaysOn cluster
@@ -61,17 +62,16 @@ node 'SQL01' {
6162
setupdir=>'\\fileserver.local\SQLServer2012.en',
6263
sa_password=>'P@ssw0rd',
6364
productkey => 'key-key-key',
64-
sqlservicecredential_username => 'DOMAIN-TEST\svc-sql-puppet',
65+
sqlservicecredential_username => 'svc-sql-puppet',
6566
sqlservicecredential_password=>'P@ssw0rd',
66-
sqlagentservicecredential_username => 'DOMAIN-TEST\svc-sql-puppet',
67+
sqlagentservicecredential_username => 'svc-sql-puppet',
6768
sqlagentservicecredential_password => 'P@ssw0rd',
6869
sqladministratoraccounts => [ 'DOMAIN-TEST\svc-puppet', 'DOMAIN-TEST\Administrator' ],
6970
clusterName => 'CLDB01',
7071
clusterIP => '192.168.1.60',
7172
fileShareWitness=> '\\192.168.1.10\quorum',
7273
listenerIP => '192.168.1.61/255.255.255.0',
73-
role => 'primary',
74-
domainNetbiosName => 'DOMAIN-TEST'
74+
role => 'primary'
7575
}
7676
}
7777
@@ -83,17 +83,16 @@ node 'SQL02' {
8383
setupdir=>'\\fileserver.local\SQLServer2012.en',
8484
sa_password=>'P@ssw0rd',
8585
productkey => 'key-key-key',
86-
sqlservicecredential_username => 'DOMAIN-TEST\svc-sql-puppet',
86+
sqlservicecredential_username => 'svc-sql-puppet',
8787
sqlservicecredential_password=>'P@ssw0rd',
88-
sqlagentservicecredential_username => 'DOMAIN-TEST\svc-sql-puppet',
88+
sqlagentservicecredential_username => 'svc-sql-puppet',
8989
sqlagentservicecredential_password => 'P@ssw0rd',
9090
sqladministratoraccounts => [ 'DOMAIN-TEST\svc-puppet', 'DOMAIN-TEST\Administrator' ],
9191
clusterName => 'CLDB01',
9292
clusterIP => '192.168.1.60',
9393
fileShareWitness=> '\\192.168.1.10\quorum',
9494
listenerIP => '192.168.1.61/255.255.255.0',
95-
role => 'secondary',
96-
domainNetbiosName => 'DOMAIN-TEST'
95+
role => 'secondary'
9796
}
9897
}
9998

files/checkspn.ps1

-9
This file was deleted.

files/setspn.ps1

-6
This file was deleted.

lib/facter/domainnetbiosname.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#https://puppet.com/blog/starting-out-writing-custom-facts-windows
2+
Facter.add('domainnetbiosname') do
3+
confine :osfamily => :windows
4+
setcode do
5+
begin
6+
require 'win32ole'
7+
dnsforestname = Facter.value(:domain)
8+
wmi = WIN32OLE.connect("winmgmts:\\\\.\\root\\cimv2")
9+
win32ntdomain = wmi.ExecQuery("SELECT * FROM Win32_NTDomain WHERE DnsForestName='#{dnsforestname}'").each.first
10+
win32ntdomain.DomainName
11+
rescue
12+
nil
13+
end
14+
end
15+
end

manifests/alwaysonconfig.pp

+36-35
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,91 @@
11
class sqlserveralwayson::alwaysonconfig inherits sqlserveralwayson {
2-
2+
33
#Enable AlwaysOn on MSSQL service
4-
dsc_xsqlserveralwaysonservice{'EnableAlwaysOn':
4+
dsc_sqlalwaysonservice{'EnableAlwaysOn':
55
dsc_ensure => 'Present',
6-
dsc_sqlserver => $hostname,
7-
dsc_sqlinstancename => 'MSSQLSERVER',
6+
dsc_servername => $hostname,
7+
dsc_instancename => 'MSSQLSERVER',
88
dsc_restarttimeout => 15,
99
dsc_psdscrunascredential => {'user' => $setup_svc_username, 'password' => $setup_svc_password}
1010
}->
11-
11+
1212
# Adding the required service account to allow the cluster to log into SQL
13-
dsc_xsqlserverlogin{'AddNTServiceClusSvc':
13+
dsc_sqlserverlogin{'AddNTServiceClusSvc':
1414
dsc_ensure => 'Present',
1515
dsc_name => 'NT SERVICE\ClusSvc',
1616
dsc_logintype => 'WindowsUser',
17-
dsc_sqlserver => $hostname,
18-
dsc_sqlinstancename => 'MSSQLSERVER',
17+
dsc_servername => $hostname,
18+
dsc_instancename => 'MSSQLSERVER',
1919
dsc_psdscrunascredential => {'user' => $setup_svc_username, 'password' => $setup_svc_password}
2020
}->
2121

2222
# Add the required permissions to the cluster service login
23-
dsc_xsqlserverpermission{'AddNTServiceClusSvcPermissions':
23+
dsc_sqlserverpermission{'AddNTServiceClusSvcPermissions':
2424
dsc_ensure => 'Present',
25-
dsc_nodename => $hostname,
25+
dsc_servername => $hostname,
2626
dsc_instancename => 'MSSQLSERVER',
2727
dsc_principal => 'NT SERVICE\ClusSvc',
2828
dsc_permission => ['AlterAnyAvailabilityGroup', 'ViewServerState'],
2929
dsc_psdscrunascredential => {'user' => $setup_svc_username, 'password' => $setup_svc_password}
3030
}->
3131

32-
dsc_xsqlserverendpoint{'SQLServerEndpoint':
32+
dsc_sqlserverendpoint{'SQLServerEndpoint':
3333
dsc_endpointname => 'HADR',
3434
dsc_ensure => 'Present',
3535
dsc_port => '5022',
36-
dsc_sqlserver => $fqdn,
37-
dsc_sqlinstancename => 'MSSQLSERVER',
36+
dsc_servername => $fqdn,
37+
dsc_instancename => 'MSSQLSERVER',
3838
dsc_psdscrunascredential => {'user' => $setup_svc_username, 'password' => $setup_svc_password}
39-
}
40-
41-
dsc_xsqlserverendpointpermission{'SQLConfigureEndpointPermission':
39+
}->
40+
41+
dsc_sqlserverendpointpermission{'SQLConfigureEndpointPermission':
4242
dsc_ensure => 'Present',
43-
dsc_nodename => $hostname,
43+
dsc_servername => $hostname,
4444
dsc_instancename => 'MSSQLSERVER',
4545
dsc_name => 'HADR',
46-
dsc_principal => $sqlservicecredential_username,
46+
dsc_principal => "${domainnetbiosname}\\$sqlservicecredential_username",
4747
dsc_permission => 'CONNECT',
4848
dsc_psdscrunascredential => {'user' => $setup_svc_username, 'password' => $setup_svc_password}
4949
}
50-
50+
5151
if ( $role == 'primary' ) {
5252
# Create the availability group on the instance tagged as the primary replica
53-
dsc_xsqlserveralwaysonavailabilitygroup{'CreateSQLAvailabilityGroup':
53+
dsc_sqlag{'CreateSQLAvailabilityGroup':
5454
dsc_ensure => 'Present',
5555
dsc_name => $clusterName,
56-
dsc_sqlserver => $hostname,
57-
dsc_sqlinstancename => 'MSSQLSERVER',
56+
dsc_servername => $hostname,
57+
dsc_instancename => 'MSSQLSERVER',
58+
dsc_availabilitymode => 'SynchronousCommit',
5859
dsc_psdscrunascredential => {'user' => $setup_svc_username, 'password' => $setup_svc_password},
59-
require => [ Dsc_xsqlserveralwaysonservice['EnableAlwaysOn'] , Dsc_xsqlserverendpoint['SQLServerEndpoint'] ]
60+
require => [ Dsc_sqlalwaysonservice['EnableAlwaysOn'] , Dsc_sqlserverendpoint['SQLServerEndpoint'] ]
6061
}
61-
62-
dsc_xsqlserveravailabilitygrouplistener{'AvailabilityGroupListener':
62+
63+
dsc_sqlaglistener{'AvailabilityGroupListener':
6364
dsc_ensure => 'Present',
64-
dsc_nodename => $fqdn,
65+
dsc_servername => $fqdn,
6566
dsc_instancename => 'MSSQLSERVER',
6667
dsc_availabilitygroup => $clusterName,
6768
dsc_name => "${clusterName}LI",
6869
dsc_ipaddress => $listenerIP,
6970
dsc_port => 1433,
7071
dsc_psdscrunascredential => {'user' => $setup_svc_username, 'password' => $setup_svc_password},
71-
require => [ Dsc_xsqlserveralwaysonavailabilitygroup['CreateSQLAvailabilityGroup'] ]
72+
require => [ Dsc_sqlag['CreateSQLAvailabilityGroup'] ]
7273
}
73-
74+
7475
}
7576
else {
76-
77-
dsc_xsqlserveralwaysonavailabilitygroupreplica{'SQLAvailabilityGroupAddReplica':
77+
78+
dsc_sqlagreplica{'SQLAvailabilityGroupAddReplica':
7879
dsc_ensure => 'Present',
7980
dsc_name => $hostname,
8081
dsc_availabilitygroupname => $clusterName,
81-
dsc_sqlserver => $hostname,
82-
dsc_sqlinstancename => 'MSSQLSERVER',
83-
dsc_primaryreplicasqlserver => $clusterName,
84-
dsc_primaryreplicasqlinstancename => 'MSSQLSERVER',
82+
dsc_servername => $hostname,
83+
dsc_instancename => 'MSSQLSERVER',
84+
dsc_primaryreplicaservername => $clusterName,
85+
dsc_primaryreplicainstancename => 'MSSQLSERVER',
8586
dsc_endpointhostname => $hostname,
8687
dsc_psdscrunascredential => {'user' => $setup_svc_username, 'password' => $setup_svc_password},
87-
require => [ Dsc_xsqlserveralwaysonservice['EnableAlwaysOn'] , Dsc_xsqlserverendpoint['SQLServerEndpoint'] ]
88+
require => [ Dsc_sqlalwaysonservice['EnableAlwaysOn'] , Dsc_sqlserverendpoint['SQLServerEndpoint'] ]
8889
}
8990
}
9091
}

manifests/clusterconfig.pp

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
class sqlserveralwayson::clusterconfig inherits sqlserveralwayson {
2-
2+
33
if ( $role == 'primary' ) {
4-
#Failover cluster creation
5-
dsc_xcluster{'CreateFailoverCluster':
6-
dsc_name => $clusterName,
7-
dsc_staticipaddress => $clusterIP,
8-
dsc_domainadministratorcredential => {'user' => $setup_svc_username, 'password' => $setup_svc_password}
9-
}
10-
11-
#File share whitness configuration
12-
#Warning, bug https://github.com/PowerShell/xFailOverCluster/issues/35 on Windows 2016
13-
dsc_xclusterquorum{'SetQuorumToNodeAndDiskMajority':
14-
dsc_issingleinstance => 'Yes',
15-
dsc_type => 'NodeAndFileShareMajority',
16-
dsc_resource => $fileShareWitness,
17-
require => Dsc_xcluster['CreateFailoverCluster']
18-
}
19-
20-
}
21-
else {
22-
dsc_xwaitforcluster{'SecondaryReplicaWaitForCluster':
23-
dsc_name => $clusterName,
24-
dsc_retryintervalsec => 10,
4+
#Failover cluster creation
5+
dsc_xcluster{'CreateFailoverCluster':
6+
dsc_name => $clusterName,
7+
dsc_staticipaddress => $clusterIP,
8+
dsc_domainadministratorcredential => {'user' => $setup_svc_username, 'password' => $setup_svc_password}
9+
}
10+
11+
#File share whitness configuration
12+
#Warning, bug https://github.com/PowerShell/xFailOverCluster/issues/35 on Windows 2016
13+
dsc_xclusterquorum{'SetQuorumToNodeAndDiskMajority':
14+
dsc_issingleinstance => 'Yes',
15+
dsc_type => 'NodeAndFileShareMajority',
16+
dsc_resource => $fileShareWitness,
17+
require => Dsc_xcluster['CreateFailoverCluster']
18+
}
19+
20+
}
21+
else {
22+
dsc_xwaitforcluster{'SecondaryReplicaWaitForCluster':
23+
dsc_name => $clusterName,
24+
dsc_retryintervalsec => 10,
2525
dsc_retrycount => 6
26-
}
27-
28-
dsc_xcluster{'JoinCluster':
29-
dsc_name => $clusterName,
26+
}
27+
28+
dsc_xcluster{'JoinCluster':
29+
dsc_name => $clusterName,
3030
dsc_staticipaddress => $clusterIP,
3131
dsc_domainadministratorcredential => {'user' => $setup_svc_username, 'password' => $setup_svc_password},
3232
require => Dsc_xwaitforcluster['SecondaryReplicaWaitForCluster']
3333
}
34-
}
35-
}
34+
}
35+
}

0 commit comments

Comments
 (0)