64 lines
1.8 KiB
YAML
64 lines
1.8 KiB
YAML
---
|
|
- name: Create SQL Server staging directory
|
|
ansible.windows.win_file:
|
|
path: "{{ mssql_staging_dir }}"
|
|
state: directory
|
|
|
|
- name: Download SQL Server 2022 setup bootstrapper
|
|
ansible.windows.win_get_url:
|
|
url: "{{ mssql_bootstrapper_url }}"
|
|
dest: "{{ mssql_bootstrapper_path }}"
|
|
timeout: 120
|
|
|
|
- name: Download SQL Server 2022 ISO via bootstrapper
|
|
ansible.windows.win_command: >-
|
|
"{{ mssql_bootstrapper_path }}"
|
|
/Action=Download
|
|
/MEDIATYPE=ISO
|
|
/MEDIAPATH="{{ mssql_staging_dir }}"
|
|
/QUIET
|
|
args:
|
|
creates: "{{ mssql_iso_path }}"
|
|
timeout: 3600
|
|
|
|
- name: Find downloaded SQL Server ISO
|
|
ansible.windows.win_find:
|
|
paths: "{{ mssql_staging_dir }}"
|
|
patterns: "*.iso"
|
|
register: iso_files
|
|
|
|
- name: Fail if no ISO found in staging directory
|
|
ansible.builtin.fail:
|
|
msg: >-
|
|
No ISO file found in {{ mssql_staging_dir }}.
|
|
The bootstrapper download may have failed.
|
|
Check {{ mssql_staging_dir }} on the target host.
|
|
when: iso_files.files | length == 0
|
|
|
|
- name: Mount SQL Server 2022 ISO
|
|
ansible.windows.win_powershell:
|
|
script: |
|
|
$ErrorActionPreference = 'Stop'
|
|
$imagePath = '{{ iso_files.files[0].path }}'
|
|
|
|
$diskImage = Get-DiskImage -ImagePath $imagePath
|
|
if (-not $diskImage.Attached) {
|
|
Mount-DiskImage -ImagePath $imagePath | Out-Null
|
|
}
|
|
|
|
$driveLetter = (Get-DiskImage -ImagePath $imagePath | Get-Volume).DriveLetter
|
|
if (-not $driveLetter) {
|
|
throw "ISO mounted but no drive letter was assigned"
|
|
}
|
|
|
|
$Ansible.Result = "${driveLetter}:"
|
|
register: mount_result
|
|
|
|
- name: Set SQL Server ISO drive letter fact
|
|
ansible.builtin.set_fact:
|
|
mssql_iso_drive: "{{ mount_result.result }}"
|
|
|
|
- name: Show mounted drive letter
|
|
ansible.builtin.debug:
|
|
msg: "SQL Server 2022 ISO mounted at {{ mssql_iso_drive }} ({{ iso_files.files[0].path }})"
|