From 3bcf84cf7ce00b08e10af0ec9501191aed2d4868 Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Thu, 19 Mar 2026 15:36:56 -0600 Subject: [PATCH] test: ensure role gathers the facts it uses by having test clear_facts before include_role The role gathers the facts it uses. For example, if the user uses `ANSIBLE_GATHERING=explicit`, the role uses the `setup` module with the facts and subsets it requires. This change allows us to test this. Before every role invocation, the test will use `meta: clear_facts` so that the role starts with no facts. Create a task file tests/tasks/run_role_with_clear_facts.yml to do the tasks to clear the facts and run the role. Note that this means we don't need to use `gather_facts` for the tests. Some vars defined using `ansible_facts` have been changed to be defined with `set_fact` instead. This is because of the fact that `vars` are lazily evaluated - the var might be referenced when the facts have been cleared, and will issue an error like `ansible_facts["distribution"] is undefined`. This is typically done for blocks that have a `when` condition that uses `ansible_facts` and the block has a role invocation using run_role_with_clear_facts.yml These have been rewritten to define the `when` condition using `set_fact`. This is because the `when` condition is evaluated every time a task is invoked in the block, and if the facts are cleared, this will raise an undefined variable error. Signed-off-by: Rich Megginson --- tests/playbooks/tests_ad_integration.yml | 3 +- .../tests_ad_integration_join_false.yml | 3 +- .../tests_ad_integration_w_keytab.yml | 3 +- .../tasks/assert_fail_on_unsupported_ver.yml | 23 +++++++----- tests/tasks/run_role_with_clear_facts.yml | 37 +++++++++++++++++++ tests/tasks/tests_ha_single.yml | 27 +++++++------- tests/tasks/tests_idempotency.yml | 12 ++---- tests/tasks/tests_input_sql_file.yml | 21 ++++------- tests/tasks/tests_password.yml | 18 +++------ tests/tasks/tests_tcp_firewall.yml | 9 ++--- tests/tasks/tests_tls.yml | 26 +++++-------- tests/tasks/upgrade_and_assert.yml | 9 ++--- tests/tests_2019_upgrade.yml | 14 +++---- tests/tests_2022_upgrade.yml | 14 +++---- tests/tests_accept_eula.yml | 3 +- tests/tests_configure_ha_cluster_external.yml | 13 +++---- ...onfigure_ha_cluster_external_read_only.yml | 3 +- .../tests_configure_ha_cluster_read_scale.yml | 3 +- tests/tests_default_2019.yml | 3 +- tests/tests_ha_single_2017.yml | 1 - tests/tests_ha_single_2019.yml | 1 - tests/tests_ha_single_2022.yml | 1 - tests/tests_idempotency_2017.yml | 1 - tests/tests_idempotency_2019.yml | 1 - tests/tests_idempotency_2022.yml | 1 - tests/tests_include_vars_from_parent.yml | 1 - tests/tests_selinux_enforcing_2022.yml | 22 ++++++----- 27 files changed, 133 insertions(+), 140 deletions(-) create mode 100644 tests/tasks/run_role_with_clear_facts.yml diff --git a/tests/playbooks/tests_ad_integration.yml b/tests/playbooks/tests_ad_integration.yml index df1a8058..dce53716 100644 --- a/tests/playbooks/tests_ad_integration.yml +++ b/tests/playbooks/tests_ad_integration.yml @@ -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 diff --git a/tests/playbooks/tests_ad_integration_join_false.yml b/tests/playbooks/tests_ad_integration_join_false.yml index 5bcdf455..1576f13d 100644 --- a/tests/playbooks/tests_ad_integration_join_false.yml +++ b/tests/playbooks/tests_ad_integration_join_false.yml @@ -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 diff --git a/tests/playbooks/tests_ad_integration_w_keytab.yml b/tests/playbooks/tests_ad_integration_w_keytab.yml index 3f909496..8f176e42 100644 --- a/tests/playbooks/tests_ad_integration_w_keytab.yml +++ b/tests/playbooks/tests_ad_integration_w_keytab.yml @@ -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 diff --git a/tests/tasks/assert_fail_on_unsupported_ver.yml b/tests/tasks/assert_fail_on_unsupported_ver.yml index e9a8bd52..13fa9783 100644 --- a/tests/tasks/assert_fail_on_unsupported_ver.yml +++ b/tests/tasks/assert_fail_on_unsupported_ver.yml @@ -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: diff --git a/tests/tasks/run_role_with_clear_facts.yml b/tests/tasks/run_role_with_clear_facts.yml new file mode 100644 index 00000000..bf19181c --- /dev/null +++ b/tests/tasks/run_role_with_clear_facts.yml @@ -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) diff --git a/tests/tasks/tests_ha_single.yml b/tests/tasks/tests_ha_single.yml index f224b230..67b418e7 100644 --- a/tests/tasks/tests_ha_single.yml +++ b/tests/tasks/tests_ha_single.yml @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/tests/tasks/tests_idempotency.yml b/tests/tasks/tests_idempotency.yml index 07c0dc31..6b74ea2f 100644 --- a/tests/tasks/tests_idempotency.yml +++ b/tests/tasks/tests_idempotency.yml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/tasks/tests_input_sql_file.yml b/tests/tasks/tests_input_sql_file.yml index e662cf5a..1ae8c3bc 100644 --- a/tests/tasks/tests_input_sql_file.yml +++ b/tests/tasks/tests_input_sql_file.yml @@ -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 @@ -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 @@ -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') }}" @@ -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') }}" @@ -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 @@ -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 @@ -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" diff --git a/tests/tasks/tests_password.yml b/tests/tasks/tests_password.yml index 1be6c57c..ebb3f132 100644 --- a/tests/tasks/tests_password.yml +++ b/tests/tasks/tests_password.yml @@ -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 @@ -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) @@ -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) @@ -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] @@ -79,8 +75,7 @@ __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) @@ -88,8 +83,7 @@ - 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] diff --git a/tests/tasks/tests_tcp_firewall.yml b/tests/tasks/tests_tcp_firewall.yml index 6331c422..bf3906e4 100644 --- a/tests/tasks/tests_tcp_firewall.yml +++ b/tests/tasks/tests_tcp_firewall.yml @@ -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 @@ -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 @@ -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 diff --git a/tests/tasks/tests_tls.yml b/tests/tasks/tests_tls.yml index 5f75e570..167a0944 100644 --- a/tests/tasks/tests_tls.yml +++ b/tests/tasks/tests_tls.yml @@ -66,10 +66,9 @@ - name: Test relative and full path with certs on control node block: - name: Run role - include_role: - name: linux-system-roles.mssql - public: true + include_tasks: tasks/run_role_with_clear_facts.yml vars: + __sr_public: true mssql_tls_enable: true mssql_tls_cert: "{{ __mssql_cert_tempfile.path }}" mssql_tls_private_key: "{{ __mssql_pvk_tempfile.path | basename }}" @@ -92,10 +91,9 @@ # Test disabling TLS encryption - name: Disable TLS encryption - include_role: - name: linux-system-roles.mssql - public: true + include_tasks: tasks/run_role_with_clear_facts.yml vars: + __sr_public: true mssql_tls_enable: false - name: Verify connectivity and settings @@ -128,10 +126,9 @@ mssql_tls_private_key: "{{ __mssql_pvk_tempfile.path | basename }}" - name: Test with certs on managed nodes - include_role: - name: linux-system-roles.mssql - public: true + include_tasks: tasks/run_role_with_clear_facts.yml vars: + __sr_public: true mssql_tls_enable: true mssql_tls_cert: "{{ __mssql_cert_tempfile.path }}" mssql_tls_private_key: "{{ __mssql_pvk_tempfile.path }}" @@ -148,8 +145,7 @@ # Test disabling TLS encryption - name: Disable TLS encryption - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml vars: mssql_tls_enable: false @@ -161,10 +157,9 @@ # Test mssql_tls_certificates - name: Test with certs created by the certificate role - include_role: - name: linux-system-roles.mssql - public: true + include_tasks: tasks/run_role_with_clear_facts.yml vars: + __sr_public: true mssql_tls_enable: true mssql_tls_certificates: - name: mssql_2019_cert @@ -182,7 +177,6 @@ # Disable TLS encryption for future tests - name: Disable TLS encryption - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml vars: mssql_tls_enable: false diff --git a/tests/tasks/upgrade_and_assert.yml b/tests/tasks/upgrade_and_assert.yml index 05ebe85c..c21078e6 100644 --- a/tests/tasks/upgrade_and_assert.yml +++ b/tests/tasks/upgrade_and_assert.yml @@ -7,12 +7,10 @@ mssql_version: "{{ __mssql_version }}" block: - name: Upgrade to {{ __mssql_version }} - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml - name: Upgrade again to test idempotency - should report not changed - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml rescue: - name: Assert that upgrading EL 7 to 2022 fails when: @@ -45,8 +43,7 @@ - name: >- Upgrade to new version on mssql new version {{ __mssql_prev_version }} - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml vars: mssql_version: "{{ __mssql_prev_version }}" diff --git a/tests/tests_2019_upgrade.yml b/tests/tests_2019_upgrade.yml index 36496540..78083004 100644 --- a/tests/tests_2019_upgrade.yml +++ b/tests/tests_2019_upgrade.yml @@ -18,10 +18,9 @@ - name: Verify the failure when mssql_version is provided incorrectly block: - name: Run the role with incorrect mssql_version - include_role: - name: linux-system-roles.mssql - public: true + include_tasks: tasks/run_role_with_clear_facts.yml vars: + __sr_public: true mssql_version: 2018 - name: Unreachable task @@ -39,9 +38,9 @@ - name: Verify the failure when mssql_version is not provided block: - name: Run the role with incorrect mssql_version - include_role: - name: linux-system-roles.mssql - public: true + include_tasks: tasks/run_role_with_clear_facts.yml + vars: + __sr_public: true - name: Unreachable task fail: @@ -56,8 +55,7 @@ in ansible_failed_result.msg - name: Set up MSSQL 2017 - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml vars: mssql_version: 2017 mssql_password: "p@55w0rD" diff --git a/tests/tests_2022_upgrade.yml b/tests/tests_2022_upgrade.yml index 901454c9..e2b55fb2 100644 --- a/tests/tests_2022_upgrade.yml +++ b/tests/tests_2022_upgrade.yml @@ -18,10 +18,9 @@ - name: Verify the failure when mssql_version is provided incorrectly block: - name: Run the role with incorrect mssql_version - include_role: - name: linux-system-roles.mssql - public: true + include_tasks: tasks/run_role_with_clear_facts.yml vars: + __sr_public: true mssql_version: 2018 - name: Unreachable task @@ -39,9 +38,9 @@ - name: Verify the failure when mssql_version is not provided block: - name: Run the role with incorrect mssql_version - include_role: - name: linux-system-roles.mssql - public: true + include_tasks: tasks/run_role_with_clear_facts.yml + vars: + __sr_public: true - name: Unreachable task fail: @@ -56,8 +55,7 @@ in ansible_failed_result.msg - name: Set up MSSQL 2019 - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml vars: mssql_version: 2019 mssql_password: "p@55w0rD" diff --git a/tests/tests_accept_eula.yml b/tests/tests_accept_eula.yml index b4388b83..313bc13a 100644 --- a/tests/tests_accept_eula.yml +++ b/tests/tests_accept_eula.yml @@ -23,8 +23,7 @@ - name: Verify the failure on a fresh host when required vars undefined block: - name: Run the role with default parameters - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml - name: Unreachable task fail: diff --git a/tests/tests_configure_ha_cluster_external.yml b/tests/tests_configure_ha_cluster_external.yml index 322ce1db..a9ce2417 100644 --- a/tests/tests_configure_ha_cluster_external.yml +++ b/tests/tests_configure_ha_cluster_external.yml @@ -134,12 +134,11 @@ when: mssql_version is version('2022', '>=') block: - name: Run on all hosts to configure contained AG + include_tasks: tasks/run_role_with_clear_facts.yml vars: mssql_ha_ag_is_contained: true mssql_ha_ag_reuse_system_db: false - include_role: - name: linux-system-roles.mssql - public: true + __sr_public: true - name: Verify is_contained status when: __mssql_ha_is_primary | bool @@ -155,12 +154,11 @@ mssql_pre_input_sql_file: [] - name: Run with contained=true reuse_system_db=true + include_tasks: tasks/run_role_with_clear_facts.yml vars: mssql_ha_ag_is_contained: true mssql_ha_ag_reuse_system_db: true - include_role: - name: linux-system-roles.mssql - public: true + __sr_public: true - name: Verify is_contained status when: __mssql_ha_is_primary | bool @@ -172,8 +170,7 @@ include_tasks: tasks/cleanup_ag.yml - name: Run with contained=false - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml vars: mssql_ha_ag_is_contained: false diff --git a/tests/tests_configure_ha_cluster_external_read_only.yml b/tests/tests_configure_ha_cluster_external_read_only.yml index fe0e92cb..8c7b47c6 100644 --- a/tests/tests_configure_ha_cluster_external_read_only.yml +++ b/tests/tests_configure_ha_cluster_external_read_only.yml @@ -134,8 +134,7 @@ tasks_from: test_setup.yml - name: Run to configure AG - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml - name: Wait for the cluster to finish configuration command: crm_resource --wait diff --git a/tests/tests_configure_ha_cluster_read_scale.yml b/tests/tests_configure_ha_cluster_read_scale.yml index fac00ea3..f47eb703 100644 --- a/tests/tests_configure_ha_cluster_read_scale.yml +++ b/tests/tests_configure_ha_cluster_read_scale.yml @@ -65,8 +65,7 @@ when: mssql_ha_replica_type == 'primary' - name: Run on all hosts to configure read-scale cluster - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml - name: Verify that the database exists on the secondary servers vars: diff --git a/tests/tests_default_2019.yml b/tests/tests_default_2019.yml index c4620b03..78f942c8 100644 --- a/tests/tests_default_2019.yml +++ b/tests/tests_default_2019.yml @@ -8,8 +8,7 @@ - name: Verify that by default the role fails with EULA not accepted block: - name: Run the role with default parameters - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml - name: Unreachable task fail: diff --git a/tests/tests_ha_single_2017.yml b/tests/tests_ha_single_2017.yml index eabf4b96..ff20badf 100644 --- a/tests/tests_ha_single_2017.yml +++ b/tests/tests_ha_single_2017.yml @@ -11,7 +11,6 @@ # modprobe softdog doesn't work in containers because softdog is not in the # container image - tests::booted - gather_facts: true vars: __mssql_single_node_test: "{{ ansible_play_hosts_all | length == 1 }}" mssql_debug: true diff --git a/tests/tests_ha_single_2019.yml b/tests/tests_ha_single_2019.yml index 371415d6..dee95509 100644 --- a/tests/tests_ha_single_2019.yml +++ b/tests/tests_ha_single_2019.yml @@ -11,7 +11,6 @@ # modprobe softdog doesn't work in containers because softdog is not in the # container image - tests::booted - gather_facts: true vars: __mssql_single_node_test: "{{ ansible_play_hosts_all | length == 1 }}" mssql_debug: true diff --git a/tests/tests_ha_single_2022.yml b/tests/tests_ha_single_2022.yml index 92a906f5..ca2a620c 100644 --- a/tests/tests_ha_single_2022.yml +++ b/tests/tests_ha_single_2022.yml @@ -11,7 +11,6 @@ # modprobe softdog doesn't work in containers because softdog is not in the # container image - tests::booted - gather_facts: true vars: __mssql_single_node_test: "{{ ansible_play_hosts_all | length == 1 }}" mssql_debug: true diff --git a/tests/tests_idempotency_2017.yml b/tests/tests_idempotency_2017.yml index 734dc8eb..2252d05b 100644 --- a/tests/tests_idempotency_2017.yml +++ b/tests/tests_idempotency_2017.yml @@ -2,7 +2,6 @@ --- - name: Ensure that the role is idempotent hosts: all - gather_facts: false vars: mssql_accept_microsoft_odbc_driver_for_sql_server_eula: true mssql_accept_microsoft_cli_utilities_for_sql_server_eula: true diff --git a/tests/tests_idempotency_2019.yml b/tests/tests_idempotency_2019.yml index 7fa9fc33..dccbf66c 100644 --- a/tests/tests_idempotency_2019.yml +++ b/tests/tests_idempotency_2019.yml @@ -2,7 +2,6 @@ --- - name: Ensure that the role is idempotent hosts: all - gather_facts: false vars: mssql_accept_microsoft_odbc_driver_for_sql_server_eula: true mssql_accept_microsoft_cli_utilities_for_sql_server_eula: true diff --git a/tests/tests_idempotency_2022.yml b/tests/tests_idempotency_2022.yml index f56b6b53..16cd8e0a 100644 --- a/tests/tests_idempotency_2022.yml +++ b/tests/tests_idempotency_2022.yml @@ -2,7 +2,6 @@ --- - name: Ensure that the role is idempotent hosts: all - gather_facts: false vars: mssql_accept_microsoft_odbc_driver_for_sql_server_eula: true mssql_accept_microsoft_cli_utilities_for_sql_server_eula: true diff --git a/tests/tests_include_vars_from_parent.yml b/tests/tests_include_vars_from_parent.yml index a7e0c85c..a7979d73 100644 --- a/tests/tests_include_vars_from_parent.yml +++ b/tests/tests_include_vars_from_parent.yml @@ -1,7 +1,6 @@ --- - name: Test role include variable override hosts: all - gather_facts: true tasks: - name: Run test in a block to clean up in always block: diff --git a/tests/tests_selinux_enforcing_2022.yml b/tests/tests_selinux_enforcing_2022.yml index 8bdbfd9b..95be047f 100644 --- a/tests/tests_selinux_enforcing_2022.yml +++ b/tests/tests_selinux_enforcing_2022.yml @@ -2,7 +2,6 @@ --- - name: Test mssql_run_selinux_confined hosts: all - gather_facts: false vars: mssql_accept_microsoft_odbc_driver_for_sql_server_eula: true mssql_accept_microsoft_cli_utilities_for_sql_server_eula: true @@ -15,14 +14,19 @@ - name: Assert expected failures on unsupported platforms include_tasks: tasks/assert_fail_on_unsupported_ver.yml + - name: Set fact for selinux confined unsupported pre-RHEL9 + set_fact: + __mssql_selinux_unsupported_pre_rhel9: >- + {{ + ansible_facts['distribution'] in ['CentOS', 'RedHat'] + and ansible_facts['distribution_major_version'] is version('9', '<') + }} + - name: Check error message on not supported hosts and clean up - when: - - ansible_facts["distribution"] in ['CentOS', 'RedHat'] - - ansible_facts["distribution_major_version"] is version('9', '<') + when: __mssql_selinux_unsupported_pre_rhel9 | bool block: - name: Check error message on not supported hosts - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml vars: mssql_manage_selinux: true mssql_run_selinux_confined: true @@ -42,8 +46,7 @@ - name: Run test in a block to clean up in always block: - name: Run with selinux_confined - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml vars: mssql_manage_selinux: true mssql_run_selinux_confined: true @@ -65,8 +68,7 @@ selinux_state: permissive - name: Run without selinux_confined - include_role: - name: linux-system-roles.mssql + include_tasks: tasks/run_role_with_clear_facts.yml vars: mssql_manage_selinux: false mssql_run_selinux_confined: false