Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .github/workflows/ansible-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,21 @@ jobs:
update: "false"
use-cache: "true"
wsl-version: 1
additional-packages: |
git
${{ matrix.python }}
python3-pip
openssh-client

# archive.ubuntu.com/security.ubuntu.com occasionally serve a Packages file that doesn't
# match the just-fetched InRelease hash (mirror mid-sync). Retrying almost always succeeds,
# so do our own apt-get here instead of relying on setup-wsl's one-shot additional-packages.
- name: Install WSL packages (with retry) # zizmor: ignore[template-injection] -- matrix.python is a controlled enum value (python3)
run: |
echo 'Acquire::Retries "3";' | sudo tee /etc/apt/apt.conf.d/80-retries > /dev/null
for attempt in 1 2 3; do
if sudo apt-get update && sudo apt-get install -y git ${{ matrix.python }} python3-pip openssh-client; then
exit 0
fi
echo "apt-get failed (attempt $attempt), retrying..."
sleep 10
done
exit 1

- name: Get Linux workspace path
shell: pwsh
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# lowlydba.sqlserver Collection for Ansible<!-- omit in toc -->

![lowlydba.sqlserver](docs/images/hero.png)

Comment thread
Copilot marked this conversation as resolved.
# lowlydba.sqlserver Collection for Ansible <!-- omit in toc -->
[![CI](https://github.com/lowlydba/lowlydba.sqlserver/actions/workflows/ansible-test.yml/badge.svg)](https://github.com/lowlydba/lowlydba.sqlserver/actions/workflows/ansible-test.yml)
[![CI (Windows)](https://github.com/lowlydba/lowlydba.sqlserver/actions/workflows/ansible-test-windows.yml/badge.svg)](https://github.com/lowlydba/lowlydba.sqlserver/actions/workflows/ansible-test-windows.yml)
[![codecov](https://codecov.io/gh/lowlydba/lowlydba.sqlserver/branch/main/graph/badge.svg?token=3TW3VBCn9N)](https://codecov.io/gh/lowlydba/lowlydba.sqlserver)
Expand Down
5 changes: 5 additions & 0 deletions changelogs/fragments/381-integration-test-gaps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bugfixes:
- backup, restore - Fix ``changed`` being reported as ``false`` in ``check_mode``, since ``Backup-DbaDatabase``/``Restore-DbaDatabase`` return no output under ``-WhatIf`` (https://github.com/lowlydba/lowlydba.sqlserver/issues/381).
- availability_group - Fix ``changed`` being incorrectly reported as ``true`` on an unchanged AG. ``Get-DbaAvailabilityGroup``'s SMO object never populates ``FailureConditionLevel``/``HealthCheckTimeout`` (they read back as unset defaults), and ``sys.availability_groups`` is a cache of the WSFC cluster resource's copy, so it's empty for AGs with ``cluster_type`` set to ``None``. Since neither source can be trusted, both properties are now excluded from the idempotency diff; they're still applied via ``Set-DbaAvailabilityGroup`` whenever another property change triggers an update (https://github.com/lowlydba/lowlydba.sqlserver/issues/381).
minor_changes:
- Add check-mode assertions for the ``backup`` and ``restore`` integration test targets, add idempotency assertions for the ``availability_group`` and ``ag_replica`` targets, and exercise a non-default ``deployment_method`` in the ``install_script`` targets (https://github.com/lowlydba/lowlydba.sqlserver/issues/381).
Binary file added docs/images/hero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions docs/images/hero.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion plugins/modules/availability_group.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ try {
if ($null -ne $isDistributedAg) {
$setAgSplat.Add("IsDistributedAvailabilityGroup", [bool]$isDistributedAg)
}
$compareProperty = $setAgSplat.Keys | Where-Object { $_ -ne "AllAvailabilityGroups" }
# FailureConditionLevel/HealthCheckTimeout are excluded from the diff: Get-DbaAvailabilityGroup's
# SMO object never populates them (they read back as unset defaults), and sys.availability_groups
# is just a cache of the WSFC cluster resource's copy, so it's empty for ClusterType None AGs
# (no cluster resource to cache from). There's no reliable way to read the real value back, so
# drift on these two can't be detected. They're still applied via Set-DbaAvailabilityGroup below
# whenever another property change triggers an update.
$compareProperty = $setAgSplat.Keys | Where-Object { $_ -notin @("AllAvailabilityGroups", "FailureConditionLevel", "HealthCheckTimeout") }
$agDiff = Get-DesiredStateDiff -Current $existingAG -Desired $setAgSplat -Property $compareProperty
if ($agDiff.Count -gt 0) {
$output = $existingAG | Set-DbaAvailabilityGroup @setAgSplat
Expand Down
4 changes: 4 additions & 0 deletions plugins/modules/backup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ try {
if ($null -ne $output) {
$resultData = ConvertTo-SerializableObject -InputObject $output
$module.Result.data = $resultData
}
# Backup-DbaDatabase returns nothing under -WhatIf, but a backup is never a no-op, so report
# changed based on check_mode too, not just on whether an output object came back.
if ($checkMode -or $null -ne $output) {
$module.Result.changed = $true
}
$module.ExitJson()
Expand Down
4 changes: 4 additions & 0 deletions plugins/modules/restore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ try {
if ($null -ne $output) {
$resultData = ConvertTo-SerializableObject -InputObject $output
$module.Result.data = $resultData
}
# Restore-DbaDatabase returns nothing under -WhatIf, but a restore is never a no-op, so report
# changed based on check_mode too, not just on whether an output object came back.
if ($checkMode -or $null -ne $output) {
$module.Result.changed = $true
}
$module.ExitJson()
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/targets/backup/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@
- result.data.End != None
- result.data.Duration != None
- result is changed

- name: Backup a database in check mode
lowlydba.sqlserver.backup:
sql_instance: "{{ sqlserver_instance }}"
sql_username: "{{ sqlserver_username }}"
sql_password: "{{ sqlserver_password }}"
database: "{{ database_name }}"
block_size: "16kb"
check_mode: true
register: result
- assert:
that:
- result is changed
1 change: 1 addition & 0 deletions tests/integration/targets/install_script/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- name: Install a script in no log mode
lowlydba.sqlserver.install_script:
no_log_version: true
deployment_method: "SingleTransaction"
register: result
- assert:
that:
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/targets/win_ag_listener/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
failover_mode: "Manual"
availability_mode: "AsynchronousCommit"
force: true
port: 1433
listener_port: 1433
module_defaults:
lowlydba.sqlserver.availability_group:
sql_instance: "{{ sqlserver_instance }}"
Expand All @@ -24,7 +24,7 @@
sql_password: "{{ sqlserver_password }}"
ag_name: "{{ ag_name }}"
listener_name: "{{ listener_name }}"
port: "{{ port }}"
port: "{{ listener_port }}"
ip_address:
- "192.168.6.9"
subnet_mask:
Expand Down Expand Up @@ -52,7 +52,7 @@
- result.data.SqlInstance != None
- result.data.AvailabilityGroup == ag_name
- result.data.Name == listener_name
- result.data.PortNumber == port
- result.data.PortNumber == listener_port
- result is changed

- name: Change ag listener port
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/targets/win_ag_replica/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@
- result.data.FailoverMode == failover_mode
- result is changed

- name: Set replica again (idempotency check)
lowlydba.sqlserver.ag_replica:
session_timeout: 20
endpoint_url: "TCP://{{ ag.data.SqlInstance }}:5022"
read_only_routing_list: "{{ ag.data.SqlInstance }}"
read_only_routing_connection_url: "TCP://{{ ag.data.SqlInstance }}:1433"
register: result
- assert:
that:
- result is not changed

always:
- name: Drop availability group
lowlydba.sqlserver.availability_group:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
- result.data.AvailabilityReplicas != None
- result is changed

- name: Create availability group again (idempotency check)
lowlydba.sqlserver.availability_group:
register: result
- assert:
that:
- result is not changed

- name: Change availability group
lowlydba.sqlserver.availability_group:
dtc_support_enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
lowlydba.sqlserver.install_script:
no_log_version: true
path: "{{ script_file.dest }}"
deployment_method: "SingleTransaction"
register: result
- assert:
that:
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/targets/win_restore/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@
database: "{{ database_name }}"
register: backup_result

- name: Restore a database in check mode
lowlydba.sqlserver.restore:
sql_instance: "{{ sqlserver_instance }}"
sql_username: "{{ sqlserver_username }}"
sql_password: "{{ sqlserver_password }}"
database: "{{ restore_database }}"
path: "{{ backup_result.data.BackupPath }}"
replace_db_name_in_file: true
block_size: "16kb"
destination_file_suffix: "_new"
destination_file_prefix: "db_"
check_mode: true
register: result
- assert:
that:
- result is changed

- name: Restore a database
lowlydba.sqlserver.restore:
sql_instance: "{{ sqlserver_instance }}"
Expand All @@ -29,6 +46,7 @@
that:
- result.data.SqlInstance != None
- result.data.Database == restore_database
- result is changed

- name: Test error when restoring to an existing database
lowlydba.sqlserver.restore:
Expand Down
Loading