Debian Codegraph @

ansible_collections/lowlydba/sqlserver/plugins/modules/dba_multitool.ps1

raw
1 #!powershell
2 # -*- coding: utf-8 -*-
3
4 # (c) 2022, John McCall (@lowlydba)
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 #AnsibleRequires -CSharpUtil Ansible.Basic
8 #AnsibleRequires -PowerShell ansible_collections.lowlydba.sqlserver.plugins.module_utils._SqlServerUtils
9 #Requires -Modules @{ ModuleName="dbatools"; ModuleVersion="2.0.0" }
10
11 $ErrorActionPreference = "Stop"
12 $spec = @{
13 supports_check_mode = $true
14 options = @{
15 branch = @{type = 'str'; required = $false; choices = @('master', 'development') }
16 local_file = @{type = 'str'; required = $false }
17 database = @{type = 'str'; required = $true }
18 force = @{type = 'bool'; required = $false; default = $false }
19 }
20 }
21
22 $module = [Ansible.Basic.AnsibleModule]::Create($args, $spec, @(Get-LowlyDbaSqlServerAuthSpec))
23 $sqlInstance, $sqlCredential = Get-SqlCredential -Module $module
24 $database = $module.Params.database
25 $branch = $module.Params.branch
26 $localFile = $module.Params.local_file
27 $force = $module.Params.force
28 $checkMode = $module.Checkmode
29 $PSDefaultParameterValues = @{ "*:EnableException" = $true; "*:Confirm" = $false; "*:WhatIf" = $checkMode }
30
31 $multiToolSplat = @{
32 SqlInstance = $sqlInstance
33 SqlCredential = $sqlCredential
34 Database = $database
35 Force = $force
36 }
37 if ($null -ne $localFile) {
38 $multiToolSplat.LocalFile = $localFile
39 }
40 if ($null -ne $branch) {
41 $multiToolSplat.Branch = $branch
42 }
43
44 try {
45 $output = Install-DbaMultiTool @multiToolSplat
46 $module.Result.changed = $true
47
48 # output is an array for each stored proc,
49 # rollup output into a single result
50 $errorProcs = $output | Where-Object Status -eq "Error"
51 if ($errorProcs) {
52 $output = $errorProcs[0] | Select-Object -ExcludeProperty Name
53 }
54 else {
55 $output = $output[0] | Select-Object -ExcludeProperty Name
56 }
57 if ($null -ne $output) {
58 $resultData = ConvertTo-SerializableObject -InputObject $output
59 $module.Result.data = $resultData
60 }
61 $module.ExitJson()
62 }
63 catch {
64 $module.FailJson("Installing DBA-MultiTool failed: $($_.Exception.Message)", $_)
65 }