Skip to content

Commit

Permalink
Take setup tasks form ha_cluster role, the mssql_ha_replica_type fact
Browse files Browse the repository at this point in the history
  • Loading branch information
spetrosi committed May 12, 2022
1 parent 946662e commit 9a66932
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
41 changes: 26 additions & 15 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,12 @@
'synchronous', 'witness', 'absent'
when: mssql_ha_configure | bool

# Verifying if 'mssql_ha_replica_type = primary' is provided as a global
# variable when running against a single host for running in CI
- name: Verify that 'mssql_ha_replica_type = primary' is provided correctly
- name: Verify that 'mssql_ha_replica_type = primary' is provided once
assert:
that: >-
(
mssql_ha_replica_type == 'primary' and
ansible_play_hosts_all | length == 1
) or
(
ansible_play_hosts_all |
that: ansible_play_hosts_all |
map('extract', hostvars, 'mssql_ha_replica_type') |
select('match', '^primary$') |
length == 1
)
fail_msg: >-
You must set the mssql_ha_replica_type variable to 'primary' for one of
your managed nodes
Expand Down Expand Up @@ -474,6 +465,14 @@
- mssql_ha_configure | bool
- mssql_ha_replica_type == 'primary'
block:
# This is required because by default variables in vars/main.yml are
# mapped into global variables and the role needs them in host variables
- name: Set host variables
set_fact:
__mssql_ha_availability_mode: "{{ __mssql_ha_availability_mode }}"
__mssql_ha_failover_mode: "{{ __mssql_ha_failover_mode }}"
__mssql_ha_seeding_mode: "{{ __mssql_ha_seeding_mode }}"

- name: Ensure the {{ __mssql_server_ha_packages }} package
package:
name: "{{ __mssql_server_ha_packages }}"
Expand Down Expand Up @@ -587,6 +586,10 @@
- key
changed_when: false

- name: Fail because this rescue block does not actually rescue failed tasks
fail:
msg: Configuration tasks failed

- name: Configure availability group on replicas
when:
- mssql_ha_configure | bool
Expand Down Expand Up @@ -697,7 +700,6 @@
vars:
ha_cluster_cluster_name: "{{ mssql_ha_ag_name }}"
ha_cluster_hacluster_password: "{{ mssql_ha_hacluster_password | quote }}"
ha_cluster_enable_repos: false
ha_cluster_cluster_properties:
- attrs:
- name: cluster-recheck-interval
Expand Down Expand Up @@ -735,9 +737,18 @@
- attrs:
- name: notify
value: true
# If RHEL > 8.3
- name: on_fail
value: demote
# If RHEL > 8.3, set on_fail: demote.
# Else, set notify: true again as a workaround
- name: "{{
'on_fail'
if ansible_distribution_version is version('8.3', '>')
else 'notify'
}}"
value: "{{
'demote'
if ansible_distribution_version is version('8.3', '>')
else true
}}"
ha_cluster_constraints_colocation:
- resource_leader:
id: ag_cluster-clone
Expand Down
1 change: 0 additions & 1 deletion tasks/set_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
- name: Set platform/version specific variables
include_vars: "{{ __mssql_vars_file }}"
loop:
- main.yml
- "{{ ansible_os_family }}.yml"
- "{{ ansible_distribution }}.yml"
- "{{ ansible_distribution }}_{{ ansible_distribution_major_version }}.yml"
Expand Down
13 changes: 0 additions & 13 deletions tests/tasks/ha_cluster_setup_test.yml

This file was deleted.

19 changes: 14 additions & 5 deletions tests/tests_configure_ha_cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
mssql_password: "p@55w0rD"
mssql_edition: Evaluation
mssql_ha_db_name: ExampleDB
mssql_ha_listener_port: 5022
mssql_ha_replica_type: primary
tasks:
# - name: Open firewall ports for TCP connection to SQL Server
# vars:
Expand All @@ -24,15 +22,25 @@
# runtime: true
# include_role:
# name: fedora.linux_system_roles.firewall

- name: Set the mssql_ha_replica_type fact to appear in hostvars
set_fact:
mssql_ha_replica_type: primary

- name: Configure SQL Server and create an ExampleDB database on primary
vars:
mssql_input_sql_file: create_example_db.j2
include_role:
name: linux-system-roles.mssql
when: mssql_ha_replica_type == 'primary'

- name: Set up test environment for the ha_cluster role
include_tasks: tasks/ha_cluster_setup_test.yml
- name: Set up test environment for the ha_cluster role in CI
include_role:
name: fedora.linux_system_roles.ha_cluster
tasks_from: ../../../tests/ha_cluster/tasks/{{ item }}
loop:
- setup_test.yml
- setup_sbd.yml

- name: Run on all hosts to configure HA cluster
vars:
Expand All @@ -42,11 +50,12 @@
mssql_ha_cert_name: mssql_cert
mssql_ha_master_key_password: "p@55w0rD1"
mssql_ha_private_key_password: "p@55w0rD2"
mssql_ha_listener_port: 5022
mssql_ha_endpoint_name: Hadr_endpoint
mssql_ha_login: pacemakerLogin
mssql_ha_login_password: "p@55w0rD3"
mssql_ha_hacluster_password: "p@55w0rD4"
mssql_ha_virtual_ip: 192.168.122.254
mssql_ha_virtual_ip: 192.168.1.254
# mssql_ha_reset_cert: true
include_role:
name: linux-system-roles.mssql

0 comments on commit 9a66932

Please sign in to comment.