Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add mssql_ha_ag_is_contained and mssql_ha_ag_reuse_system_db to allow creating AG as contained and reuse system database #337

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,25 @@ Default: `[]`

Type: `list`

#### mssql_ha_ag_is_contained

if true, the ag created will be contained

if false, the var mssql_ha_ag_reuse_system_db will be false

Default: `false`

Type: `bool`

#### mssql_ha_ag_reuse_system_db

if true, the contained ag will be reuse system database

Default: `false`

Type: `bool`


### Configuring Pacemaker Variables

With these variables, you can specify whether to configure Pacemaker HA solution and its configuration.
Expand Down Expand Up @@ -936,6 +955,8 @@ Default: `false`

Type: `bool`



### Always On Availability Group Example Playbooks

Examples in this section show how to use the role to configure SQL Server and configure it for high availability in different environments.
Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@
mssql_ha_endpoint_port: 5022
mssql_ha_cert_name: null
mssql_ha_private_key_password: null
mssql_ha_master_key_password: null

Check warning on line 50 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Detect non-inclusive language

`master` may be insensitive, use `primary`, `source`, `initiator,requester`, `controller,host`, `director` instead
mssql_ha_reset_cert: false
mssql_ha_endpoint_name: null
mssql_ha_ag_name: null
mssql_ha_db_names: []
mssql_ha_ag_is_contained: false
mssql_ha_ag_reuse_system_db: false
# if mssql_ha_ag_is_contained is false, mssql_ha_ag_reuse_system_db will be false

mssql_ha_prep_for_pacemaker: "{{ mssql_ha_ag_cluster_type | lower != 'none' }}"
mssql_ha_virtual_ip: null
Expand Down
11 changes: 10 additions & 1 deletion templates/configure_ag.j2
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ successfully';
{% endfor %}
END

{% if not mssql_ha_ag_is_contained %}
{% set is_contained_is_reuse_system_db = "" %}
{% elif mssql_ha_ag_is_contained %}
{% set is_contained_is_reuse_system_db = ",CONTAINED" %}
{% if mssql_ha_ag_reuse_system_db %}
{% set is_contained_is_reuse_system_db = is_contained_is_reuse_system_db + ",REUSE_SYSTEM_DATABASES" %}
{% endif %}
{% endif %}

IF NOT EXISTS (
SELECT name, cluster_type_desc
FROM sys.availability_groups
Expand All @@ -219,7 +228,7 @@ BEGIN
CREATE AVAILABILITY GROUP {{ mssql_ha_ag_name }}
WITH (
DB_FAILOVER = {{ __mssql_ha_db_failover }},
CLUSTER_TYPE = {{ mssql_ha_ag_cluster_type }}
CLUSTER_TYPE = {{ mssql_ha_ag_cluster_type }}{{ is_contained_is_reuse_system_db }}
)
FOR REPLICA ON
{# Sort ansible_play_hosts #}
Expand Down
129 changes: 129 additions & 0 deletions tests/test_contained_ag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#all:
# hosts:
# 192.168.200.136:
# ansible_user: root
# ansible_ssh_pass: "1q!"
# mssql_ha_replica_type: primary
# ha_cluster:
# node_name: node-4
# pcs_address: node-4
# corosync_addresses:
# - 192.168.200.136
# 192.168.200.137:
# ansible_user: root
# ansible_ssh_pass: "1q!"
# mssql_ha_replica_type: synchronous
# ha_cluster:
# node_name: node-5
# pcs_address: node-5
# corosync_addresses:
# - 192.168.200.137
# 192.168.200.138:
# ansible_user: root
# ansible_ssh_pass: "1q!"
# mssql_ha_replica_type: synchronous
# ha_cluster:
# node_name: node-6
# pcs_address: node-6
# corosync_addresses:
# - 192.168.200.138
#
---
- name: Test contained AG
hosts: all
vars:
mssql_accept_microsoft_odbc_driver_17_for_sql_server_eula: true
mssql_accept_microsoft_odbc_driver_for_sql_server_eula: true
mssql_accept_microsoft_cli_utilities_for_sql_server_eula: true
mssql_accept_microsoft_sql_server_standard_eula: true
mssql_version: 2022
mssql_password: "p@55w0rD"
mssql_edition: 2Q48Q-PB48J-DRCVN-GB844-X2H4Q
mssql_datadir: "/data/mssql/1433/database/"
mssql_logdir: "/data/mssql/1433/database/"
# mssql_pre_input_sql_content: "USE MASTER;CREATE DATABASE ExampleDB2;BACKUP DATABASE ExampleDB2 TO DISK='nil'with compression;"

mssql_manage_firewall: true
mssql_run_selinux_confined: false
mssql_ha_configure: true
mssql_manage_ha_cluster: true
mssql_ha_prep_for_pacemaker: true
mssql_ha_ag_cluster_type: external
mssql_ha_ag_is_contained: true
mssql_ha_ag_reuse_system_db: true
mssql_ha_endpoint_port: 5022
mssql_ha_cert_name: ExampleCert
mssql_ha_master_key_password: "p@55w0rD1"
mssql_ha_private_key_password: "p@55w0rD2"
mssql_ha_reset_cert: true
mssql_ha_endpoint_name: Example_Endpoint
mssql_ha_ag_name: ExampleAG
mssql_ha_db_names:
- test_1
mssql_ha_login: pacemakerLogin
mssql_ha_login_password: "p@55w0rD3"
mssql_ha_virtual_ip: 192.168.200.139
ha_cluster_cluster_name: "{{ mssql_ha_ag_name }}"
ha_cluster_hacluster_password: "p@55w0rD4"
ha_cluster_cluster_properties:
- attrs:
- name: cluster-recheck-interval
value: 2min
- name: start-failure-is-fatal
value: false
- name: stonith-enabled
value: false
ha_cluster_resource_primitives:
- id: ag_cluster
agent: ocf:mssql:ag
instance_attrs:
- attrs:
- name: ag_name
value: "{{ mssql_ha_ag_name }}"
meta_attrs:
- attrs:
- name: failure-timeout
value: 60s
- id: virtualip
agent: ocf:heartbeat:IPaddr2
instance_attrs:
- attrs:
- name: ip
value: "{{ mssql_ha_virtual_ip }}"
operations:
- action: monitor
attrs:
- name: interval
value: 30s
ha_cluster_resource_clones:
- resource_id: ag_cluster
promotable: yes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
promotable: yes
promotable: true

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

promotable: yes
i copy it from the example playbook in README.md

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i copy it from the example playbook in README.md

ok - we need to fix that - Ansible now strongly prefers true/false instead of yes/no

meta_attrs:
- attrs:
- name: notify
value: true
ha_cluster_constraints_colocation:
- resource_leader:
id: ag_cluster-clone
role: Promoted
resource_follower:
id: virtualip
options:
- name: score
value: INFINITY
ha_cluster_constraints_order:
- resource_first:
id: ag_cluster-clone
action: promote
resource_then:
id: virtualip
action: start
tasks:
# - name: Set facts to create a test DB on primary as a pre task
# set_fact:
# mssql_pre_input_sql_file: create_ExampleDB.sql
# when: mssql_ha_replica_type == 'primary'

- name: Run on all hosts to configure HA cluster
include_role:
name: microsoft.sql.server
Loading