|
| 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 |
0 commit comments