diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 120e7de5..d1421188 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,19 @@ lowlydba.sqlserver Release Notes .. contents:: Topics +v0.7.0 +====== + +Release Summary +--------------- + +Add module for DBA Multitool. + +New Modules +----------- + +- dba_multitool - Install/update the DBA Multitool suite by John McCAll + v0.6.0 ====== @@ -13,6 +26,11 @@ Release Summary Adding new SPN module +Minor Changes +------------- + +- Remove CI support for Ansible 2.10 + New Modules ----------- diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 2dee1f24..8cb42d2d 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -4,135 +4,146 @@ releases: changes: release_summary: It's a release! First version to publish to Ansible Galaxy. fragments: - - v0.1.0_summary.yml + - v0.1.0_summary.yml modules: - - description: Configures a SQL Agent job. - name: agent_job - namespace: '' - - description: Configures a SQL Agent job category. - name: agent_job_category - namespace: '' - - description: Configures a SQL Agent job schedule. - name: agent_job_schedule - namespace: '' - - description: Configures a SQL Agent job step. - name: agent_job_step - namespace: '' - - description: Creates and configures a database. - name: database - namespace: '' - - description: Configures a login for the target SQL Server instance. - name: login - namespace: '' - - description: Install/update Maintenance Solution - name: maintenance_solution - namespace: '' - - description: Sets the maximum memory for a SQL Server instance. - name: memory - namespace: '' - - description: Executes a generic nonquery. - name: nonquery - namespace: '' - - description: Configures the resource governor on a SQL Server instance. - name: resource_governor - namespace: '' - - description: Configures a resource pool for use by the Resource Governor. - name: rg_resource_pool - namespace: '' - - description: Configures a workload group for use by the Resource Governor. - name: rg_workload_group - namespace: '' - - description: Make instance level system configuration changes via sp_configure. - name: sp_configure - namespace: '' - - description: Install/update sp_whoisactive by Adam Mechanic. - name: sp_whoisactive - namespace: '' - - description: Enable or disable global trace flags on a SQL Server instance. - name: traceflag - namespace: '' - release_date: '2022-03-30' + - description: Configures a SQL Agent job. + name: agent_job + namespace: "" + - description: Configures a SQL Agent job category. + name: agent_job_category + namespace: "" + - description: Configures a SQL Agent job schedule. + name: agent_job_schedule + namespace: "" + - description: Configures a SQL Agent job step. + name: agent_job_step + namespace: "" + - description: Creates and configures a database. + name: database + namespace: "" + - description: Configures a login for the target SQL Server instance. + name: login + namespace: "" + - description: Install/update Maintenance Solution + name: maintenance_solution + namespace: "" + - description: Sets the maximum memory for a SQL Server instance. + name: memory + namespace: "" + - description: Executes a generic nonquery. + name: nonquery + namespace: "" + - description: Configures the resource governor on a SQL Server instance. + name: resource_governor + namespace: "" + - description: Configures a resource pool for use by the Resource Governor. + name: rg_resource_pool + namespace: "" + - description: Configures a workload group for use by the Resource Governor. + name: rg_workload_group + namespace: "" + - description: Make instance level system configuration changes via sp_configure. + name: sp_configure + namespace: "" + - description: Install/update sp_whoisactive by Adam Mechanic. + name: sp_whoisactive + namespace: "" + - description: Enable or disable global trace flags on a SQL Server instance. + name: traceflag + namespace: "" + release_date: "2022-03-30" 0.1.1: changes: release_summary: Add database tag for Galaxy fragments: - - v0.1.1_summary.yml - release_date: '2022-03-31' + - v0.1.1_summary.yml + release_date: "2022-03-31" 0.2.0: changes: minor_changes: - - Add DbaTools module requirement to documentation and fix missing examples. - (https://github.com/lowlydba/lowlydba.sqlserver/pull/47) - - Utilize PowerShell Requires for dbatools min version needs instead of custom - function. Consolidate/standardize credential setup and serialization. (https://github.com/lowlydba/lowlydba.sqlserver/pull/48) + - Add DbaTools module requirement to documentation and fix missing examples. + (https://github.com/lowlydba/lowlydba.sqlserver/pull/47) + - Utilize PowerShell Requires for dbatools min version needs instead of custom + function. Consolidate/standardize credential setup and serialization. (https://github.com/lowlydba/lowlydba.sqlserver/pull/48) release_summary: Code cleanup, testing improvements, new _info module! fragments: - - 47-improve-module-documentation.yml - - 48-cleanup-utils.yml + - 47-improve-module-documentation.yml + - 48-cleanup-utils.yml modules: - - description: Returns basic information for a SQL Server instance. - name: instance_info - namespace: '' - release_date: '2022-04-04' + - description: Returns basic information for a SQL Server instance. + name: instance_info + namespace: "" + release_date: "2022-04-04" 0.3.0: changes: minor_changes: - - Fix logic to properly pass password policy options to function in the login - module. + - Fix logic to properly pass password policy options to function in the login + module. release_summary: New sa module and fixes for login related modules. fragments: - - 55-fix-login-param.yml - - v0.3.0-release-summary.yml + - 55-fix-login-param.yml + - v0.3.0-release-summary.yml modules: - - description: Configure the 'sa' login for security best practices. - name: sa - namespace: '' - release_date: '2022-04-05' + - description: Configure the 'sa' login for security best practices. + name: sa + namespace: "" + release_date: "2022-04-05" 0.4.0: changes: breaking_changes: - - All modules should use a bool 'enabled' instead of a string 'status' to control - object state. + - All modules should use a bool 'enabled' instead of a string 'status' to control + object state. minor_changes: - - Test for 'Name' property for sa module after dbatools release 1.1.95 standardizes - command outputs. (https://github.com/dataplat/dbatools/releases/tag/v1.1.95) + - Test for 'Name' property for sa module after dbatools release 1.1.95 standardizes + command outputs. (https://github.com/dataplat/dbatools/releases/tag/v1.1.95) release_summary: Two new AlwaysOn modules and a few consistency fixes! fragments: - - 0.4.0-release-summary.yml - - 56-test-for-login-name.yml - - 60-standardize-enabled-option.yml + - 0.4.0-release-summary.yml + - 56-test-for-login-name.yml + - 60-standardize-enabled-option.yml modules: - - description: Configures availability group(s). - name: availability_group - namespace: '' - - description: Enable or disable HADR. - name: hadr - namespace: '' - release_date: '2022-04-27' + - description: Configures availability group(s). + name: availability_group + namespace: "" + - description: Enable or disable HADR. + name: hadr + namespace: "" + release_date: "2022-04-27" 0.5.0: changes: minor_changes: - - Remove CI support for Ansible 2.10 - release_summary: CI and testing improvements, along with the final availability + - Remove CI support for Ansible 2.10 + release_summary: + CI and testing improvements, along with the final availability group module ag_replica. fragments: - - 70-deprecate-ansible-2.10.yml - - release-summary.yml + - 70-deprecate-ansible-2.10.yml + - release-summary.yml modules: - - description: Configures an availability group listener. - name: ag_listener - namespace: '' - - description: Configures an availability group replica. - name: ag_replica - namespace: '' - release_date: '2022-05-11' + - description: Configures an availability group listener. + name: ag_listener + namespace: "" + - description: Configures an availability group replica. + name: ag_replica + namespace: "" + release_date: "2022-05-11" 0.6.0: changes: release_summary: Adding new SPN module fragments: - - release-summary-0-6-0.yml + - release-summary-0-6-0.yml modules: - - description: Configures SPNs for SQL Server. - name: spn - namespace: '' - release_date: '2022-05-20' + - description: Configures SPNs for SQL Server. + name: spn + namespace: "" + release_date: "2022-05-20" + 0.7.0: + changes: + release_summary: Add module for DBA Multitool. + fragments: + - release-summary-0-7-0.yml + modules: + - description: Install/update the DBA Multitool suite by John McCAll + name: dba_multitool + namespace: "" + release_date: "2022-05-21" diff --git a/galaxy.yml b/galaxy.yml index b81ade58..ff55b76a 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -2,7 +2,7 @@ namespace: lowlydba name: sqlserver -version: 0.6.0 +version: 0.7.0 readme: README.md authors: - John McCall (github.com/lowlydba) diff --git a/plugins/modules/dba_multitool.ps1 b/plugins/modules/dba_multitool.ps1 new file mode 100644 index 00000000..bc17a7b3 --- /dev/null +++ b/plugins/modules/dba_multitool.ps1 @@ -0,0 +1,65 @@ +#!powershell +# -*- coding: utf-8 -*- + +# (c) 2022, John McCall (@lowlydba) +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +#AnsibleRequires -CSharpUtil Ansible.Basic +#AnsibleRequires -PowerShell ansible_collections.lowlydba.sqlserver.plugins.module_utils._SqlServerUtils +#Requires -Modules @{ ModuleName="dbatools"; ModuleVersion="1.1.95" } + +$ErrorActionPreference = "Stop" +$spec = @{ + supports_check_mode = $true + options = @{ + branch = @{type = 'str'; required = $false; choices = @('master', 'development') } + local_file = @{type = 'str'; required = $false } + database = @{type = 'str'; required = $true } + force = @{type = 'bool'; required = $false; default = $false } + } +} + +$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec, @(Get-LowlyDbaSqlServerAuthSpec)) +$sqlInstance, $sqlCredential = Get-SqlCredential -Module $module +$database = $module.Params.database +$branch = $module.Params.branch +$localFile = $module.Params.local_file +$force = $module.Params.force +$checkMode = $module.Checkmode +$PSDefaultParameterValues = @{ "*:EnableException" = $true; "*:Confirm" = $false; "*:WhatIf" = $checkMode } + +$multiToolSplat = @{ + SqlInstance = $sqlInstance + SqlCredential = $sqlCredential + Database = $database + Force = $force +} +if ($null -ne $localFile) { + $multiToolSplat.LocalFile = $localFile +} +if ($null -ne $branch) { + $multiToolSplat.Branch = $branch +} + +try { + $output = Install-DbaMultiTool @multiToolSplat + $module.Result.changed = $true + + # output is an array for each stored proc, + # rollup output into a single result + $errorProcs = $output | Where-Object Status -eq "Error" + if ($errorProcs) { + $output = $errorProcs[0] | Select-Object -ExcludeProperty Name + } + else { + $output = $output[0] | Select-Object -ExcludeProperty Name + } + if ($null -ne $output) { + $resultData = ConvertTo-SerializableObject -InputObject $output + $module.Result.data = $resultData + } + $module.ExitJson() +} +catch { + $module.FailJson("Installing DBA-MultiTool failed: $($_.Exception.Message)", $_) +} diff --git a/plugins/modules/dba_multitool.py b/plugins/modules/dba_multitool.py new file mode 100644 index 00000000..be969838 --- /dev/null +++ b/plugins/modules/dba_multitool.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2022, John McCall (@lowlydba) +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +DOCUMENTATION = r''' +--- +module: dba_multitool +short_description: Install/update the DBA Multitool suite by John McCAll +description: + - A wrapper for Install-DbaMultiTool to fetch the latest version of the scripts, or install from a local cached version. +version_added: 0.7.0 +options: + sql_instance: + description: + - The target SQL Server instance or instances. Server version must be SQL Server version 2005 or higher. + type: str + required: true + local_file: + description: + - Specifies the path to a local file to install DBA MultiTool from. This should be the zip file as distributed by the maintainers. + If this parameter is not specified, the latest version will be downloaded and installed from https://github.com/LowlyDBA/dba-multitool/. + type: str + required: false + branch: + description: + - Specifies an alternate branch of the DBA MultiTool to install. + type: str + required: false + choices: ['master', 'development'] + database: + description: + - Name of the target database. + type: str + required: true + force: + description: + - If this switch is enabled, the DBA MultiTool will be downloaded from the internet even if previously cached. + type: bool + default: false +author: "John McCall (@lowlydba)" +extends_documentation_fragment: + - lowlydba.sqlserver.sql_credentials +''' + +EXAMPLES = r''' +- name: Install DBA MultiTool + lowlydba.sqlserver.dba_multitool: + sql_instance: test-server.my.company.com + database_name: dba_tools +''' + +RETURN = r''' +data: + description: Modified output from the C(Install-DbaMultitool) function. + returned: success, but not in check_mode. + type: dict +''' diff --git a/tests/integration/targets/dba_multitool/aliases b/tests/integration/targets/dba_multitool/aliases new file mode 100644 index 00000000..4f4b6b91 --- /dev/null +++ b/tests/integration/targets/dba_multitool/aliases @@ -0,0 +1,2 @@ +context/target +setup/once/setup_sqlserver diff --git a/tests/integration/targets/dba_multitool/meta/main.yml b/tests/integration/targets/dba_multitool/meta/main.yml new file mode 100644 index 00000000..a3309752 --- /dev/null +++ b/tests/integration/targets/dba_multitool/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_sqlserver_test_plugins diff --git a/tests/integration/targets/dba_multitool/tasks/main.yml b/tests/integration/targets/dba_multitool/tasks/main.yml new file mode 100644 index 00000000..b548ee7a --- /dev/null +++ b/tests/integration/targets/dba_multitool/tasks/main.yml @@ -0,0 +1,37 @@ +--- +- name: Var block + vars: + target_database: "master" + branch: "development" + module_defaults: + lowlydba.sqlserver.dba_multitool: + sql_instance: "{{ sqlserver_instance }}" + sql_username: "{{ sqlserver_username }}" + sql_password: "{{ sqlserver_password }}" + database: "{{ target_database }}" + branch: "{{ branch }}" + tags: ["dba_multitool"] + block: + - name: Install dba_multitool + lowlydba.sqlserver.dba_multitool: + register: result + - assert: + that: + - result.data.SqlInstance != None + - result.data.ComputerName != None + - result.data.InstanceName != None + - result.data.Database == target_database + - result.data.Status in ('Installed', 'Updated') + - result is changed + + - name: Update dba_multitool + lowlydba.sqlserver.dba_multitool: + register: result + - assert: + that: + - result.data.SqlInstance != None + - result.data.ComputerName != None + - result.data.InstanceName != None + - result.data.Database == target_database + - result.data.Status == 'Updated' + - result is changed diff --git a/tests/integration/targets/win_dba_multitool/aliases b/tests/integration/targets/win_dba_multitool/aliases new file mode 100644 index 00000000..5d4e3ade --- /dev/null +++ b/tests/integration/targets/win_dba_multitool/aliases @@ -0,0 +1,5 @@ +windows/all +windows/group/2 +context/target +setup/once/setup_win_sqlserver +needs/target/dba_multitool diff --git a/tests/integration/targets/win_dba_multitool/meta/main.yml b/tests/integration/targets/win_dba_multitool/meta/main.yml new file mode 100644 index 00000000..9db0dd08 --- /dev/null +++ b/tests/integration/targets/win_dba_multitool/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - dba_multitool