# SPDX-License-Identifier: MIT
---
- name: Ensure that the role runs when EULA are accepted
  hosts: all
  vars:
    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' if (ansible_distribution_major_version is version('9', '>=') or
      ansible_distribution in ['Fedora'])
      else '2017' }}"
    __mssql_test_confined_supported: "{{
      ((ansible_distribution in ['CentOS', 'RedHat']) and
      (ansible_distribution_major_version is version('9', '>='))) or
      (ansible_distribution in ['Fedora']) }}"
    mssql_manage_selinux: "{{ __mssql_test_confined_supported }}"
    mssql_run_selinux_confined: "{{ __mssql_test_confined_supported }}"
    __mssql_gather_facts_no_log: true
  tasks:
    - name: Run test in a block to clean up in always
      block:
        - 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

            - name: Unreachable task
              fail:
                msg: The above task must fail

          rescue:
            - name: Assert that the role failed with variables undefined
              assert:
                that: >-
                  'You must define the following variables to set up MSSQL' in
                  ansible_failed_result.msg.0
      always:
        - name: Clean up after the role invocation
          include_tasks: tasks/cleanup.yml
