summaryrefslogtreecommitdiffstats
path: root/ansible_collections/lowlydba/sqlserver/plugins/modules/database.ps1
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:35 +0000
commit7fec0b69a082aaeec72fee0612766aa42f6b1b4d (patch)
treeefb569b86ca4da888717f5433e757145fa322e08 /ansible_collections/lowlydba/sqlserver/plugins/modules/database.ps1
parentReleasing progress-linux version 7.7.0+dfsg-3~progress7.99u1. (diff)
downloadansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.tar.xz
ansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.zip
Merging upstream version 9.4.0+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/lowlydba/sqlserver/plugins/modules/database.ps1')
-rw-r--r--ansible_collections/lowlydba/sqlserver/plugins/modules/database.ps120
1 files changed, 16 insertions, 4 deletions
diff --git a/ansible_collections/lowlydba/sqlserver/plugins/modules/database.ps1 b/ansible_collections/lowlydba/sqlserver/plugins/modules/database.ps1
index 4c3e3c9d0..dc030946c 100644
--- a/ansible_collections/lowlydba/sqlserver/plugins/modules/database.ps1
+++ b/ansible_collections/lowlydba/sqlserver/plugins/modules/database.ps1
@@ -6,7 +6,7 @@
#AnsibleRequires -CSharpUtil Ansible.Basic
#AnsibleRequires -PowerShell ansible_collections.lowlydba.sqlserver.plugins.module_utils._SqlServerUtils
-#Requires -Modules @{ ModuleName="dbatools"; ModuleVersion="1.1.112" }
+#Requires -Modules @{ ModuleName="dbatools"; ModuleVersion="2.0.0" }
$ErrorActionPreference = "Stop"
@@ -22,6 +22,7 @@ $spec = @{
secondary_maxdop = @{type = 'int'; required = $false; }
compatibility = @{type = 'str'; required = $false; }
rcsi = @{type = 'bool'; required = $false; }
+ only_accessible = @{type = 'bool'; default = 'true' }
state = @{type = 'str'; required = $false; default = 'present'; choices = @('present', 'absent') }
}
}
@@ -35,6 +36,7 @@ $logFilePath = $module.Params.log_file_path
$owner = $module.Params.owner
$compatibility = $module.Params.compatibility
[nullable[bool]]$rcsiEnabled = $module.Params.rcsi
+[nullable[bool]]$onlyAccessible = $module.Params.only_accessible
[nullable[int]]$maxDop = $module.Params.maxdop
[nullable[int]]$secondaryMaxDop = $module.Params.secondary_maxdop
$state = $module.Params.state
@@ -48,7 +50,7 @@ try {
SqlInstance = $sqlInstance
SqlCredential = $sqlCredential
Database = $database
- OnlyAccessible = $true
+ OnlyAccessible = $onlyAccessible
ExcludeSystem = $true
EnableException = $true
}
@@ -61,8 +63,18 @@ try {
if ($state -eq "absent") {
if ($null -ne $existingDatabase) {
- $existingDatabase | Remove-DbaDatabase -WhatIf:$checkMode -EnableException -Confirm:$false
- $module.Result.changed = $true
+ try {
+ $droppedDatabase = $existingDatabase | Remove-DbaDatabase -WhatIf:$checkMode -EnableException -Confirm:$false
+ if ($droppedDatabase.Status -eq "Dropped") {
+ $module.Result.changed = $true
+ }
+ elseif ($droppedDatabase.Status -ne "Dropped") {
+ $module.FailJson("Database [$database] was not dropped. " + $droppedDatabase.Status)
+ }
+ }
+ catch {
+ $module.FailJson("An exception occurred while trying to drop database [$database].", $_)
+ }
}
$module.ExitJson()
}