# SPDX-License-Identifier: MIT
---
- name: Ensure that the role is idempotent when changing the sa user password
  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: 2019
  tasks:
    - name: Set up MSSQL
      include_role:
        name: microsoft.sql.server
      vars:
        mssql_password: "p@55w0rD"
        mssql_edition: Evaluation

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

    - name: >-
        Change the password with default settings.
        Should report Changed.
      include_role:
        name: microsoft.sql.server
      vars:
        mssql_password: "p@55w0rD11"

    - name: Verify settings
      include_tasks: tasks/verify_settings.yml
      vars:
        __verify_mssql_password: "p@55w0rD11"

    - name: Change the IP address setting.
      include_role:
        name: microsoft.sql.server
      vars:
        mssql_ip_address: 127.0.0.1

    - name: >-
        Change the password with a custom IP address.
        Should report Changed.
      include_role:
        name: microsoft.sql.server
      vars:
        mssql_password: "p@55w0rD"

    - name: Verify settings
      include_tasks: tasks/verify_settings.yml
      vars:
        __verify_mssql_password: "p@55w0rD"

    - name: Change the TCP port setting.
      include_role:
        name: microsoft.sql.server
      vars:
        mssql_tcp_port: 1432

    - name: >-
        Change the password with a custom TCP port and IP address.
        Should report Changed.
      include_role:
        name: microsoft.sql.server
      vars:
        mssql_password: "p@55w0rD11"

    - name: Verify settings
      include_tasks: tasks/verify_settings.yml
      vars:
        __verify_mssql_password: "p@55w0rD11"

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