| 1 |
#!/usr/bin/python |
| 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 |
DOCUMENTATION = r''' |
| 8 |
--- |
| 9 |
module: availability_group |
| 10 |
short_description: Configures availability group(s) |
| 11 |
description: |
| 12 |
- Configures SQL Server Availability Group(s) with up to one replica. |
| 13 |
version_added: 0.4.0 |
| 14 |
options: |
| 15 |
sql_instance_secondary: |
| 16 |
description: |
| 17 |
- The secondary SQL Server instance for the new Availability Group. |
| 18 |
type: str |
| 19 |
required: false |
| 20 |
sql_username_secondary: |
| 21 |
description: |
| 22 |
- Username for SQL Authentication for the secondary replica. |
| 23 |
type: str |
| 24 |
required: false |
| 25 |
sql_password_secondary: |
| 26 |
description: |
| 27 |
- Password for SQL Authentication for the secondary replica. |
| 28 |
type: str |
| 29 |
required: false |
| 30 |
database: |
| 31 |
description: |
| 32 |
- Name of the database to create the Availability Group for. |
| 33 |
type: str |
| 34 |
required: false |
| 35 |
aliases: |
| 36 |
- database_name |
| 37 |
ag_name: |
| 38 |
description: |
| 39 |
- Name of the Availability Group. |
| 40 |
type: str |
| 41 |
required: true |
| 42 |
all_ags: |
| 43 |
description: |
| 44 |
- Apply changes to all availability groups on the instance. Only used for configuring existing availability groups. |
| 45 |
type: bool |
| 46 |
required: false |
| 47 |
shared_path: |
| 48 |
description: |
| 49 |
- The network share where the backups will be backed up and restored from. |
| 50 |
type: str |
| 51 |
required: false |
| 52 |
dtc_support_enabled: |
| 53 |
description: |
| 54 |
- Enables Dtc support. |
| 55 |
type: bool |
| 56 |
required: false |
| 57 |
basic_availability_group: |
| 58 |
description: |
| 59 |
- Indicates whether the availability group is Basic Availability Group. |
| 60 |
type: bool |
| 61 |
required: false |
| 62 |
contained_availability_group: |
| 63 |
description: |
| 64 |
- Indicates whether the availability group is Contained. Requires DBATools >= 2.1.15 |
| 65 |
type: bool |
| 66 |
required: false |
| 67 |
version_added: "2.6.0" |
| 68 |
database_health_trigger: |
| 69 |
description: |
| 70 |
- Indicates whether the availability group triggers the database health. |
| 71 |
type: bool |
| 72 |
required: false |
| 73 |
is_distributed_ag: |
| 74 |
description: |
| 75 |
- Indicates whether the availability group is distributed. |
| 76 |
type: bool |
| 77 |
required: false |
| 78 |
healthcheck_timeout: |
| 79 |
description: |
| 80 |
- This setting used to specify the length of time, in milliseconds, |
| 81 |
that the SQL Server resource DLL should wait for information returned by the C(sp_server_diagnostics) |
| 82 |
stored procedure before reporting the Always On Failover Cluster Instance (FCI) as unresponsive. |
| 83 |
- Changes that are made to the timeout settings are effective immediately and do not require a restart of the SQL Server resource. |
| 84 |
type: int |
| 85 |
required: false |
| 86 |
failure_condition_level: |
| 87 |
description: |
| 88 |
- Specifies the different conditions that can trigger an automatic failover in Availability Group. |
| 89 |
type: str |
| 90 |
required: false |
| 91 |
choices: ['OnAnyQualifiedFailureCondition', 'OnCriticalServerErrors', 'OnModerateServerErrors', 'OnServerDown', 'OnServerUnresponsive'] |
| 92 |
cluster_type: |
| 93 |
description: |
| 94 |
- Cluster type of the Availability Group. Only supported in SQL Server 2017 and above. |
| 95 |
type: str |
| 96 |
required: false |
| 97 |
default: 'Wsfc' |
| 98 |
choices: ['Wsfc', 'External', 'None'] |
| 99 |
failover_mode: |
| 100 |
description: |
| 101 |
- Whether the replica have Automatic or Manual failover. |
| 102 |
type: str |
| 103 |
required: false |
| 104 |
default: 'Automatic' |
| 105 |
choices: ['Automatic', 'Manual'] |
| 106 |
availability_mode: |
| 107 |
description: |
| 108 |
- Whether the replica should be Asynchronous or Synchronous. |
| 109 |
- Only used in creating a new availability group. |
| 110 |
type: str |
| 111 |
required: false |
| 112 |
default: 'SynchronousCommit' |
| 113 |
choices: ['AsynchronousCommit', 'SynchronousCommit'] |
| 114 |
seeding_mode: |
| 115 |
description: |
| 116 |
- Default seeding mode for the replica. Should remain as the default otherwise manual setup may be required. |
| 117 |
type: str |
| 118 |
required: false |
| 119 |
default: 'Manual' |
| 120 |
choices: ['Automatic', 'Manual'] |
| 121 |
automated_backup_preference: |
| 122 |
description: |
| 123 |
- How to handle backup requests by default. |
| 124 |
type: str |
| 125 |
required: false |
| 126 |
default: 'Secondary' |
| 127 |
choices: ['None', 'Primary', 'Secondary', 'SecondaryOnly'] |
| 128 |
allow_null_backup: |
| 129 |
description: |
| 130 |
- Allow taking a full backup to C(NULL) if one does not exist and I(seeding_mode=Automatic). |
| 131 |
type: bool |
| 132 |
required: false |
| 133 |
force: |
| 134 |
description: |
| 135 |
- Drop and recreate the database on remote servers using fresh backup. |
| 136 |
type: bool |
| 137 |
use_last_backup: |
| 138 |
description: |
| 139 |
- Use the last full and log backup of database. A log backup must be the last backup. |
| 140 |
type: bool |
| 141 |
author: "John McCall (@lowlydba)" |
| 142 |
requirements: |
| 143 |
- L(dbatools,https://www.powershellgallery.com/packages/dbatools/) PowerShell module |
| 144 |
extends_documentation_fragment: |
| 145 |
- lowlydba.sqlserver.sql_credentials |
| 146 |
- lowlydba.sqlserver.attributes.check_mode |
| 147 |
- lowlydba.sqlserver.attributes.platform_all |
| 148 |
- lowlydba.sqlserver.state |
| 149 |
''' |
| 150 |
|
| 151 |
EXAMPLES = r''' |
| 152 |
- name: Create Availability Group |
| 153 |
lowlydba.sqlserver.availability_group: |
| 154 |
sql_instance: sql-01.myco.io |
| 155 |
ag_name: AG_MyDatabase |
| 156 |
''' |
| 157 |
|
| 158 |
RETURN = r''' |
| 159 |
data: |
| 160 |
description: Output from the C(New-DbaAvailabilityGroup) or C(Set-DbaAvailabilityGroup) function. |
| 161 |
returned: success, but not in check_mode. |
| 162 |
type: dict |
| 163 |
''' |