Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions tests/playbooks/tests_ad_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@
tasks:
# Test general scenario
- name: Set up MSSQL and configure AD authentication
include_role:
name: linux-system-roles.mssql
include_tasks: ../tasks/run_role_with_clear_facts.yml

- name: Test AD integration
include_tasks: ../tasks/verify_ad_auth.yml
Expand Down
3 changes: 1 addition & 2 deletions tests/playbooks/tests_ad_integration_join_false.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
name: linux-system-roles.ad_integration

- name: Set up MSSQL and configure AD authentication without joining to AD
include_role:
name: linux-system-roles.mssql
include_tasks: ../tasks/run_role_with_clear_facts.yml
vars:
mssql_ad_join: false
# Explicitly set kerberos vars, otherwise the value becomes null
Expand Down
3 changes: 1 addition & 2 deletions tests/playbooks/tests_ad_integration_w_keytab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
mssql_ad_keytab_file: /tmp/mssql.keytab
mssql_ad_keytab_remote_src: false
mssql_ad_sql_password: null
include_role:
name: linux-system-roles.mssql
include_tasks: ../tasks/run_role_with_clear_facts.yml

- name: Test AD integration
include_tasks: ../tasks/verify_ad_auth.yml
Expand Down
23 changes: 13 additions & 10 deletions tests/tasks/assert_fail_on_unsupported_ver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
setup:
gather_subset: min

- name: Set fact for unsupported platform/version combination
set_fact:
__mssql_assert_unsupported_platform: >-
{{ (ansible_facts['distribution'] in ['CentOS', 'RedHat'] and
ansible_facts['distribution_major_version'] is version('7', '=') and
mssql_version | int == 2022) or (
((ansible_facts['distribution'] in ['CentOS', 'RedHat'] and
ansible_facts['distribution_major_version'] is version('9', '=')) or
(ansible_facts['distribution'] in ['Fedora'])) and
mssql_version | int != 2022) }}

- name: Assert fail when used on platform where mssql_version is not supported
when: >-
(ansible_facts["distribution"] in ['CentOS', 'RedHat']
and ansible_facts["distribution_major_version"] is version('7', '=')
and mssql_version | int == 2022)
or (((ansible_facts["distribution"] in ['CentOS', 'RedHat']
and ansible_facts["distribution_major_version"] is version('9', '='))
or (ansible_facts["distribution"] in ['Fedora']))
and mssql_version | int != 2022)
when: __mssql_assert_unsupported_platform | bool
block:
- name: Run the role
vars:
mssql_password: "p@55w0rD"
mssql_edition: Evaluation
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Unreachable task
fail:
Expand Down
37 changes: 37 additions & 0 deletions tests/tasks/run_role_with_clear_facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# Task file: clear_facts, run linux-system-roles.mssql.
# Include this with include_tasks or import_tasks
# Input:
# - __sr_tasks_from: tasks_from to run - same as tasks_from in include_role
# - __sr_public: export private vars from role - same as public in include_role
# - __sr_failed_when: set to false to ignore role errors - same as failed_when in include_role
- name: Clear facts
meta: clear_facts

# note that you can use failed_when with import_role but not with include_role
# so this simulates the __sr_failed_when false case
# Q: Why do we need a separate task to run the role normally? Why not just
# run the role in the block and rethrow the error in the rescue block?
# A: Because you cannot rethrow the error in exactly the same way as the role does.
# It might be possible to exactly reconstruct ansible_failed_result but it's not worth the effort.
- name: Run the role with __sr_failed_when false
when:
- __sr_failed_when is defined
- not __sr_failed_when
block:
- name: Run the role
include_role:
name: linux-system-roles.mssql
tasks_from: "{{ __sr_tasks_from | default('main') }}"
public: "{{ __sr_public | default(false) }}"
rescue:
- name: Ignore the failure when __sr_failed_when is false
debug:
msg: Ignoring failure when __sr_failed_when is false

- name: Run the role normally
include_role:
name: linux-system-roles.mssql
tasks_from: "{{ __sr_tasks_from | default('main') }}"
public: "{{ __sr_public | default(false) }}"
when: __sr_failed_when | d(true)
27 changes: 14 additions & 13 deletions tests/tasks/tests_ha_single.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# SPDX-License-Identifier: MIT
---
- name: Set fact for EL < 8 HA configure unsupported
set_fact:
__mssql_ha_el7_configure_block: >-
{{
ansible_facts['distribution'] in ['CentOS', 'RedHat']
and ansible_facts['distribution_version'] is version('8', '<')
}}

- name: Verify that by default the role fails on EL < 8
when:
- ansible_facts["distribution"] in ['CentOS', 'RedHat']
- ansible_facts["distribution_version"] is version('8', '<')
when: __mssql_ha_el7_configure_block | bool
block:
- name: Run the role
vars:
mssql_ha_configure: true
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Unreachable task
fail:
Expand All @@ -33,8 +38,7 @@
when: ansible_play_hosts_all | length == 1
block:
- name: Run role with mssql_replica_type=primary not defined
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Unreachable task
fail:
Expand All @@ -57,11 +61,10 @@
- name: Verify fail when ag_is_contained=false,reuse_system_db=true
block:
- name: Run role with mssql_ha_ag_is_contained=false reuse_db=true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_ha_ag_is_contained: false
mssql_ha_ag_reuse_system_db: true
include_role:
name: linux-system-roles.mssql

- name: Unreachable task
fail:
Expand All @@ -78,10 +81,9 @@
when: mssql_version is version('2022', '<')
block:
- name: Run role with mssql_ha_ag_is_contained = true
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_ha_ag_is_contained: true
include_role:
name: linux-system-roles.mssql

- name: Unreachable task
fail:
Expand Down Expand Up @@ -125,8 +127,7 @@
inventory_hostname: "{{ ansible_play_hosts[0] }}" # noqa: var-naming

- name: Run on all hosts to configure HA cluster
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml

# The following tasks test if templates configure systems correctly
# Because CI runs on a single node, these templates can't be tested:
Expand Down
12 changes: 4 additions & 8 deletions tests/tasks/tests_idempotency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
include_tasks: assert_fail_on_unsupported_ver.yml

- name: Run on a fresh host and set all parameters
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_password: "p@55w0rD"
mssql_edition: Evaluation
Expand All @@ -21,8 +20,7 @@
include_tasks: mssql-sever-increase-start-limit.yml

- name: Run again with the same settings - should report not changed
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_password: "p@55w0rD"
mssql_edition: Evaluation
Expand Down Expand Up @@ -50,8 +48,7 @@
__verify_mssql_logdir: /tmp/mssql_log

- name: Run to edit settings
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_password: "p@55w0rD1"
mssql_edition: Standard
Expand All @@ -67,8 +64,7 @@
mssql_logdir_mode: '755'

- name: Run with the edited settings again - should report not changed
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_password: "p@55w0rD1"
mssql_edition: Standard
Expand Down
21 changes: 7 additions & 14 deletions tests/tasks/tests_input_sql_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
include_tasks: assert_fail_on_unsupported_ver.yml

- name: Set up MSSQL and input sql files with pre_input
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_pre_input_sql_file:
- create_example_db.j2
Expand All @@ -28,8 +27,7 @@
__mssql_sqlcmd_input.stdout

- name: Input sql files with post_input into custom storage directory
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_datadir: /tmp/mssql_data
mssql_logdir: /tmp/mssql_log
Expand Down Expand Up @@ -59,8 +57,7 @@
__verify_mssql_logdir_mode: '0700'

- name: Set up MSSQL and input sql content with pre_input
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_pre_input_sql_content:
- "{{ lookup('template', 'create_example_db.j2') }}"
Expand All @@ -76,8 +73,7 @@
__mssql_sqlcmd_input.stdout

- name: Set up MSSQL and input sql content with post_input
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_post_input_sql_content:
- "{{ lookup('file', 'sql_script.sql') }}"
Expand All @@ -92,8 +88,7 @@
- name: Verify the failure when the mssql_password var is not specified
block:
- name: Input the sql file without the mssql_password variable
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_pre_input_sql_file: sql_script.sql

Expand All @@ -111,8 +106,7 @@
- name: Verify the failure when the mssql_password var is not specified
block:
- name: Input the sql file without the mssql_password variable
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_post_input_sql_file: sql_script.sql

Expand All @@ -128,8 +122,7 @@
ansible_failed_result.msg

- name: Verify that FTS was enabled in the beginning of this test playbook
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_post_input_sql_file: verify_fts.sql
mssql_password: "p@55w0rD"
Expand Down
18 changes: 6 additions & 12 deletions tests/tasks/tests_password.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
when: __bootc_validation | d(false)

- name: Set up MSSQL
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_password: "p@55w0rD"
mssql_edition: Evaluation
Expand All @@ -24,8 +23,7 @@
- name: >-
Change the password with default settings.
Should report Changed.
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_password: "p@55w0rD11"
when: not __bootc_validation | d(false)
Expand All @@ -43,8 +41,7 @@
__mssql_verify_package_installed: true

- name: Change the IP address setting.
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_ip_address: 127.0.0.1
when: not __bootc_validation | d(false)
Expand All @@ -59,8 +56,7 @@
- name: >-
Change the password with a custom IP address.
Should report Changed.
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_password: "p@55w0rD"
mssql_tools_versions: [17, 18]
Expand All @@ -79,17 +75,15 @@
__mssql_verify_package_installed: true

- name: Change the TCP port setting.
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_tcp_port: 1432
when: not __bootc_validation | d(false)

- name: >-
Change the password with a custom TCP port and IP address.
Should report Changed.
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_password: "p@55w0rD11"
mssql_tools_versions: [18]
Expand Down
9 changes: 3 additions & 6 deletions tests/tasks/tests_tcp_firewall.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
__mssql_test_port: 1433
block:
- name: Set up SQL Server
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_password: "p@55w0rD"
mssql_edition: Evaluation
Expand All @@ -27,8 +26,7 @@
__mssql_test_port: 1433
block:
- name: Set up SQL Server
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_password: "p@55w0rD"
mssql_edition: Evaluation
Expand All @@ -45,8 +43,7 @@
__mssql_test_port: 1435
block:
- name: Set up SQL Server
include_role:
name: linux-system-roles.mssql
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
mssql_password: "p@55w0rD"
mssql_edition: Evaluation
Expand Down
Loading
Loading