Skip to content

Commit 3f0da7a

Browse files
author
Tim Hansen
committed
Add README and document guides.
Signed-off-by: Tim Hansen <[email protected]>
0 parents  commit 3f0da7a

File tree

6 files changed

+354
-0
lines changed

6 files changed

+354
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Installing SQL Server on Windows Server 2022 with Ansible
2+
Fork of https://github.com/kkolk/mssql. Adapted for Windows Server 2022.
3+
4+
Installs SQL Server on Windows Server 2022 via DSC.
5+
6+
DSC Overview: https://docs.microsoft.com/en-us/powershell/dsc/overview?view=dsc-1.1
7+
SQL Server DSC: https://github.com/dsccommunity/SqlServerDsc
8+
SQL Server DSC Options: https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/server-configuration-options-sql-server
9+
10+

handlers/main.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
# handlers file for roles/mssql
3+
- name: reboot windows
4+
win_reboot:
5+
reboot_timeout: 3600
6+
post_reboot_delay: 60
7+
when: mssql_suppress_reboot == False
8+
9+
- name: restart sqlagent
10+
win_service:
11+
name: "SQLAgent${{ mssql_instance_name|upper }}"
12+
state: restarted

inventory

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[win]
2+
winserver.dev.lan
3+
4+
[win:vars]
5+
ansible_connection = winrm
6+
ansible_winrm_transport = basic
7+
ansible_winrm_server_cert_validation = ignore
8+
ansible_user = Administrator

main.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- name: Install SQL Server Windows
2+
hosts: win
3+
tags: install_mssql
4+
roles:
5+
- { role: mssql }

roles/mssql/tasks/main.yml

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
---
2+
3+
# Load required powershell modules
4+
- name: Powershell | Check for SQLServer DSC Powershell module
5+
win_psmodule:
6+
name: SQLServerDsc
7+
state: present
8+
9+
- name: Powershell | Check for Storage DSC Powershell module
10+
win_psmodule:
11+
name: StorageDsc
12+
state: present
13+
14+
- name: Powershell | Check for ServerManager Powershell module
15+
win_psmodule:
16+
name: ServerManager
17+
state: present
18+
19+
- name: Powershell | Ensure that DBA Tools module is present
20+
win_psmodule:
21+
name: dbatools
22+
state: present
23+
24+
- name: Powershell | Check for xNetworking Powershell module
25+
win_psmodule:
26+
name: xNetworking
27+
state: present
28+
29+
- name: Windows | Install .NET Framework Core
30+
win_feature:
31+
name: NET-Framework-Core
32+
state: present
33+
34+
# Setup SQL Server Pre-Reqs
35+
- name: Windows | Install .NET Framework 3.5
36+
win_feature:
37+
name: NET-Framework-Features
38+
state: present
39+
40+
- name: Windows | Install .NET Framework 4.5 Features
41+
win_feature:
42+
name: NET-Framework-45-Features
43+
state: present
44+
include_sub_features: True
45+
46+
- name: Windows | Install Windows Process Activation Service
47+
win_feature:
48+
name: WAS
49+
state: present
50+
include_sub_features: True
51+
52+
# SQL install may fail if a pending reboot is detected
53+
# Assuming we are allowed to reboot this step will check for pending reboots
54+
# and execute a reboot, reboot activity can be controlled using the variable mssql_suppress_reboot
55+
56+
- name: Ensure that a reboot is not pending
57+
when: ansible_reboot_pending
58+
debug:
59+
msg: 'Pending reboot detected'
60+
changed_when: true
61+
notify: reboot windows
62+
63+
- meta: flush_handlers
64+
65+
- name: Fetch SQL Media Downloader
66+
win_get_url:
67+
url: "{{ mssql_installation_source }}"
68+
dest: "{{ mssql_temp_download_path }}\\SQLServer2017-SSEI-Dev.exe"
69+
70+
- name: Use Media Downloader to fetch SQL Installation CABs to {{ mssql_installation_path }}
71+
win_shell: "{{ mssql_temp_download_path }}\\SQLServer2017-SSEI-Dev.exe /Action=Download /MediaPath={{ mssql_installation_path }} /MediaType=CAB /Quiet"
72+
73+
# Job will fail if extracted media folder is not empty, quick step to ensure it's empty
74+
- name: Ensure installation media extraction path is empty
75+
win_file:
76+
path: "{{ mssql_installation_path }}\\Media"
77+
state: absent
78+
79+
- name: Extract installation media
80+
win_shell: "{{ mssql_installation_path }}\\SQLServer2017-DEV-x64-ENU.exe /X:{{ mssql_installation_path }}\\Media /Q"
81+
# If this step fails, logs are in C:\Program Files\Microsoft SQL Server\...\Setup Bootstrap\Log
82+
# it will often contain the actual error. If it shows everything passing, the issue is within the DSC logs.
83+
84+
- name: Install SQL Server
85+
win_dsc:
86+
resource_name: SQLSetup
87+
Action: Install
88+
UpdateEnabled: True
89+
SourcePath: "{{ mssql_installation_path }}\\Media"
90+
InstanceName: "{{ mssql_instance_name }}"
91+
InstallSharedDir: "{{ mssql_installshared_path }}"
92+
InstallSharedwowDir: "{{ mssql_installsharedwow_path }}"
93+
InstanceDir: "{{ mssql_instance_path }}"
94+
InstallSQLDataDir: "{{ mssql_sqlinstalldata_path }}"
95+
SQLUserDBDir: "{{ mssql_sqluserdata_path }}"
96+
SQLUserDBLogDir: "{{ mssql_sqluserlog_path }}"
97+
SQLTempDBDir: "{{ mssql_sqltempDB_path }}"
98+
SQLTempDBLogDir: "{{ mssql_sqltempDBlog_path }}"
99+
Features: "{{ mssql_features }}"
100+
SQLCollation: "{{ mssql_collation }}"
101+
BrowserSvcStartupType: "{{ mssql_browsersvc_mode }}"
102+
SuppressReboot: "{{ mssql_suppress_reboot }}"
103+
# SQL Service Account
104+
SQLSvcAccount_username: "{{ mssql_sqlsvc_account }}"
105+
SQLSvcAccount_password: "{{ mssql_sqlsvc_account_pass }}"
106+
# SQL Agent Service Account
107+
AgtSvcAccount_username: "{{ mssql_agentsvc_account }}"
108+
AgtSvcAccount_password: "{{ mssql_agentsvc_account_pass }}"
109+
# SQL Analysis Services Account
110+
ASSvcAccount_username: "{{ mssql_assvc_account }}"
111+
ASSvcAccount_password: "{{ mssql_assvc_account_pass }}"
112+
113+
# Used when installing on a network path, comment out
114+
# SourceCredential_username: "{{ ansible_user }}"
115+
# SourceCredential_password: "{{ ansible_password }}"
116+
117+
# System Admins
118+
SQLSysAdminAccounts: "{{ mssql_sysadmin_accounts }}"
119+
# Analysis Services Admins (if installed)
120+
ASSysAdminAccounts: "{{ mssql_asadmin_accounts }}"
121+
tags: install_sql
122+
123+
# Firewall configuration
124+
- name: Firewall | Allow Database Engine for instance
125+
win_dsc:
126+
resource_name: xFirewall
127+
Name: "SQL Server Database Engine instance {{ mssql_instance_name }}"
128+
Program: sqlservr.exe
129+
Ensure: present
130+
Enabled: True
131+
Profile: "Domain"
132+
Direction: "Inbound"
133+
Action: Allow
134+
Description: "Allows the Database Engine to access the network"
135+
tags: configure_firewall
136+
137+
- name: Firewall | Allow SQLBrowser for instance
138+
win_dsc:
139+
resource_name: xFirewall
140+
Name: "SQL Server Browser instance {{ mssql_instance_name }}"
141+
Service: SQLBrowser
142+
Ensure: present
143+
Enabled: True
144+
Profile: "Domain"
145+
Direction: "Inbound"
146+
Action: Allow
147+
Description: "Allows the SQL Server Browser to access the network"
148+
tags: configure_firewall
149+
150+
# Begin SQL Server configuration
151+
- name: Enable TCP Connectivity
152+
win_dsc:
153+
resource_name: SqlServerNetwork
154+
InstanceName: "{{ mssql_instance_name }}"
155+
ProtocolName: tcp
156+
TcpPort: "{{ mssql_port }}"
157+
IsEnabled: True
158+
RestartService: True
159+
tags: configure_sql
160+
161+
- name: Adjust Max Server Memory to {{ mssql_max_server_memory }}
162+
when: mssql_max_server_memory is defined
163+
win_dsc:
164+
resource_name: SqlConfiguration
165+
InstanceName: "{{ mssql_instance_name }}"
166+
ServerName: "{{ ansible_hostname }}"
167+
OptionName: max server memory (MB)
168+
OptionValue: "{{ mssql_max_server_memory }}"
169+
RestartService: False
170+
tags: configure_sql
171+
172+
- name: Adjust Min Server Memory to {{ mssql_min_server_memory }}
173+
when: mssql_min_server_memory is defined
174+
win_dsc:
175+
resource_name: SqlConfiguration
176+
ServerName: "{{ ansible_hostname }}"
177+
InstanceName: "{{ mssql_instance_name }}"
178+
OptionName: min server memory (MB)
179+
OptionValue: "{{ mssql_min_server_memory }}"
180+
tags: configure_sql
181+
182+
- name: Adjust Max Degree of Parallelism
183+
when: mssql_max_degree_of_parallelism is defined
184+
win_dsc:
185+
resource_name: SqlConfiguration
186+
ServerName: "{{ ansible_hostname }}"
187+
InstanceName: "{{ mssql_instance_name }}"
188+
OptionName: max degree of parallelism
189+
OptionValue: "{{ mssql_max_degree_of_parallelism }}"
190+
tags: configure_sql

roles/mssql/vars/main.yml

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
# installation files source
3+
mssql_installation_source: https://go.microsoft.com/fwlink/?linkid=853016
4+
5+
mssql_installation_path: C:\SQLInstall
6+
mssql_temp_download_path: C:\Users\Administrator
7+
8+
# instance details
9+
mssql_instance_name: Test
10+
mssql_drive: C
11+
mssql_userdbvol_name: userdbvol1
12+
mssql_port: 1433
13+
14+
# memory in MB
15+
# Max memory to allocate to this instance
16+
mssql_max_server_memory: 1024
17+
18+
# Memory to reserve to the OS
19+
mssql_os_memory_reservation: 512
20+
21+
# Total system memory
22+
mssql_total_system_memory: "{{ mssql_max_server_memory + mssql_os_memory_reservation }}"
23+
24+
# Suppress reboots that may occur during SQL Setup tasks
25+
# you will want to set this to True if working on a sensitive system:
26+
mssql_suppress_reboot: False
27+
28+
### Service Accounts ###
29+
30+
# SQL Service Account
31+
mssql_sqlsvc_account: Administrator
32+
mssql_sqlsvc_account_pass: redhat22
33+
34+
# SQL Agent Service Account
35+
mssql_agentsvc_account: Administrator
36+
mssql_agentsvc_account_pass: redhat22
37+
38+
# SQL Analysis Services Account
39+
mssql_assvc_account: "{{ mssql_sqlsvc_account }}"
40+
mssql_assvc_account_pass: "{{ mssql_sqlsvc_account_pass }}"
41+
42+
### File and Folder Paths ###
43+
44+
# volume paths
45+
mssql_userdbvol_path: "{{ mssql_drive }}:\\{{ mssql_userdbvol_name }}"
46+
mssql_db_accesspath: "{{ mssql_userdbvol_path }}\\DatabaseFiles"
47+
mssql_logs_accesspath: "{{ mssql_userdbvol_path }}\\DatabaseLogs"
48+
49+
# shared files paths
50+
mssql_installshared_path: C:\Program Files\Microsoft SQL Server
51+
mssql_installsharedwow_path: C:\Program Files (x86)\Microsoft SQL Server
52+
53+
# instance path
54+
mssql_instance_path: "C:\\Program Files\\Microsoft SQL Server\\{{ mssql_instance_name }}"
55+
56+
# SQL DB and Logging Paths
57+
mssql_sqlinstalldata_path: "{{ mssql_db_accesspath }}\\{{mssql_instance_name }}"
58+
mssql_sqluserdata_path: "{{ mssql_db_accesspath }}\\{{mssql_instance_name }}"
59+
mssql_sqluserlog_path: "{{ mssql_logs_accesspath }}\\{{mssql_instance_name }}"
60+
mssql_sqltempDB_path: "C:\\TempDBFiles\\Data\\{{mssql_instance_name }}"
61+
mssql_sqltempDBlog_path: "C:\\TempDBFiles\\Log\\{{mssql_instance_name }}"
62+
63+
# security mode - SQL indicates mixed-mode auth, while Windows indicates Windows Auth.
64+
mssql_security_mode: sql
65+
66+
# SA user password, if security mode is set to 'SQL'
67+
# by default for testing we'll be lazy and use the service account password,
68+
# but on live systems you should use something else:
69+
mssql_sa_password: "{{ mssql_sqlsvc_account_pass }}"
70+
71+
# features - Comma seperated list of features to be installed
72+
#
73+
# example:
74+
# mssql_features: SQLENGINE,AS
75+
#
76+
# The list of features below is untested, some may not work with DSC
77+
#
78+
# Features list:
79+
#
80+
# Database engine = SQLENGINE
81+
# Replication = REPLICATION
82+
# Full-text and semantic extractions for search = FULLTEXT
83+
# Data quality services = DQ
84+
# Analysis services = AS
85+
# Reporting services – native = RS
86+
# Reporting services – sharepoint = RS_SHP
87+
# Reporting services add-in for sharepoint products = RS_SHPWFE
88+
# Data quality client = DQC
89+
# SQL Server data tools = BIDS
90+
# Client tools connectivity = CONN
91+
# Integration services = IS
92+
# Client tools backwards compatibility = BC
93+
# Client tools SDK = SDK
94+
# Documentation components = BOL
95+
# Management tools – basic = SSMS
96+
# Management tools – advanced = ADV_SSMS
97+
# Distributed replay controller = DREPLAY_CTLR
98+
# Distributed replay client = DREPLAY_CLT
99+
# SQL client connectivity SDK = SNAC_SDK
100+
# Master data services = MDS
101+
# ADVANCEDANALYTICS Installs R Services, requires the database engine. Unattended installations require /IACCEPTROPENLICENSETERMS parameter.
102+
mssql_features: SQLENGINE,FULLTEXT,CONN
103+
104+
# Collation
105+
mssql_collation: SQL_Latin1_General_CP1_CI_AS
106+
107+
# Browser service startup mode
108+
# Specifies the startup mode for SQL Server Browser service. { Automatic | Disabled | 'Manual' }
109+
mssql_browsersvc_mode: Automatic
110+
111+
# Default Account Access
112+
# Ansible_Admin must be included so that the playbook can make configuration changes post install
113+
mssql_sysadmin_accounts:
114+
- Administrator
115+
116+
# Analysis Services Admins (if installed)
117+
mssql_asadmin_accounts: "{{ mssql_sysadmin_accounts }}"
118+
119+
# Tuning options
120+
# See: https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/configure-the-max-degree-of-parallelism-server-configuration-option
121+
mssql_max_degree_of_parallelism: 0
122+
123+
# Minimum memory to allocate to SQL
124+
#
125+
# Should remain 0 in most cases.
126+
#
127+
# see: Optimizing Server Performance Using Memory Configuration Options
128+
# https://technet.microsoft.com/en-us/library/ms177455(v=sql.105).aspx
129+
mssql_min_server_memory: 0

0 commit comments

Comments
 (0)