# SPDX-License-Identifier: MIT
---
- name: Ensure that the role is idempotent
  hosts: all
  vars:
    mssql_accept_microsoft_odbc_driver_17_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
  tasks:
    - name: Assert fail on RHEL 7 when upgrading to 2022
      include_tasks: tasks/sqlserver2022-rhel7-assert-fail.yml

    - name: Run on a fresh host and set all parameters
      include_role:
        name: microsoft.sql.server
      vars:
        mssql_password: "p@55w0rD"
        mssql_edition: Evaluation
        mssql_tcp_port: 1433
        mssql_ip_address: 0.0.0.0
        mssql_enable_sql_agent: true
        mssql_install_fts: true
        mssql_enable_ha: true
        mssql_tune_for_fua_storage: true
        mssql_install_powershell: true

    - name: Configure the mssql-server service start limit interval and burst
      include_tasks: tasks/mssql-sever-increase-start-limit.yml

    - name: Run again with the same settings - should report not changed
      include_role:
        name: microsoft.sql.server
      vars:
        mssql_password: "p@55w0rD"
        mssql_edition: Evaluation
        mssql_tcp_port: 1433
        mssql_ip_address: 0.0.0.0
        mssql_enable_sql_agent: true
        mssql_install_fts: true
        mssql_enable_ha: true
        mssql_tune_for_fua_storage: true
        mssql_install_powershell: true

    - name: Verify settings
      include_tasks: tasks/verify_settings.yml
      vars:
        __verify_mssql_password: "p@55w0rD"
        __verify_mssql_edition: Evaluation
        __verify_mssql_tcp_port: 1433
        __verify_mssql_ip_address: 0.0.0.0
        __verify_mssql_agent_is_enabled: true
        __verify_mssql_fts_is_installed: true
        __verify_mssql_ha_is_installed: true
        __verify_mssql_is_tuned_for_fua: true
        __verify_mssql_powershell_is_installed: true

    - name: Run to edit settings
      include_role:
        name: microsoft.sql.server
      vars:
        mssql_password: "p@55w0rD1"
        mssql_edition: Standard
        mssql_tcp_port: 1435
        mssql_ip_address: 127.0.0.1
        mssql_enable_sql_agent: false
        mssql_install_fts: false
        mssql_enable_ha: false
        mssql_tune_for_fua_storage: false
        mssql_install_powershell: false

    - name: Run with the edited settings again - should report not changed
      include_role:
        name: microsoft.sql.server
      vars:
        mssql_password: "p@55w0rD1"
        mssql_edition: Standard
        mssql_tcp_port: 1435
        mssql_ip_address: 127.0.0.1
        mssql_enable_sql_agent: false
        mssql_install_fts: false
        mssql_enable_ha: false
        mssql_tune_for_fua_storage: false
        mssql_install_powershell: false

    - name: Verify disabled settings
      include_tasks: tasks/verify_settings.yml
      vars:
        __verify_mssql_password: "p@55w0rD1"
        __verify_mssql_edition: Standard
        __verify_mssql_tcp_port: 1435
        __verify_mssql_ip_address: 127.0.0.1
        __verify_mssql_agent_is_enabled: false
        __verify_mssql_fts_is_installed: false
        __verify_mssql_ha_is_installed: false
        __verify_mssql_is_tuned_for_fua: false
        __verify_mssql_powershell_is_installed: false

    - name: Check the ansible_managed header in the configuration file
      include_tasks: tasks/check_header.yml
