lowlydba / lowlydba.sqlserver

:spoon: A cross-platform Ansible collection using PowerShell to configure and maintain SQL Server.
https://galaxy.ansible.com/ui/repo/published/lowlydba/sqlserver
GNU General Public License v3.0
19 stars 12 forks source link

[Bug] Taks using login module keeps returning changed true even when login already present #256

Open diegotercero opened 1 month ago

diegotercero commented 1 month ago

Describe the bug I'm using lowlydba.sqlserver.login module version 2.3.3 The return value of changed is always set to true even when the user in the server already exists.

To Reproduce

    - name: Create a login for user
      lowlydba.sqlserver.login:
        sql_instance: '{{ mssql_instance }}'
        sql_username: '{{ mssql_sa_login }}'
        sql_password: '{{ mssql_sa_password }}'
        login: '{{ mssql_user_login }}'
        password: '{{ mssql_user_password }}'
        state: present

Expected behavior If I run this taks when the user in the database doesn't exist, the return value of changed should be true, which it is. If I run when the user in the database already exists, the return value of changed should be false. Which is not the case for me, I keep getting a changed return value.

Versions:

Additional context Ansible output given : (I replaced my actuals hosts, instance names and user logins values with replacement names). For information I later used a PowerShell task using win_powershell and invoking dbatools cmdlets to add this users to the sysadmin server role (that's why in the output the user appears as a member of the sysadmin role).

TASK [Create a login for Open Media Edito user] **************************************************************************************************************************************
task path: /home/tercero/dev/infrastructure/playbooks/omserverdb.yml:22
Using module file /home/tercero/.ansible/collections/ansible_collections/lowlydba/sqlserver/plugins/modules/login.ps1
Pipelining is enabled.
<myserverhost.com> ESTABLISH WINRM CONNECTION FOR USER:  on PORT 5985 TO myserverhost.com
EXEC (via pipeline wrapper)
changed: [myserverhost.com] => {
    "changed": true,
    "data": {
        "ComputerName": "COMPUTERNAME",
        "DefaultDatabase": "master",
        "DenyLogin": false,
        "InstanceName": "INSTANCENAME",
        "IsDisabled": false,
        "IsLocked": false,
        "Language": "Français",
        "MustChangePassword": false,
        "Name": "SQL_USER",
        "Notes": null,
        "PasswordChanged": true,
        "PasswordExpirationEnabled": false,
        "PasswordPolicyEnforced": false,
        "ServerRole": "sysadmin",
        "SqlInstance": "SERVER\\INSTANCE"
    },
    "invocation": {
        "module_args": {
            "default_database": null,
            "enabled": true,
            "language": null,
            "login": "SQL_USER",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "password_expiration_enabled": null,
            "password_must_change": null,
            "password_policy_enforced": null,
            "sid": null,
            "skip_password_reset": false,
            "sql_instance": "SERVER\\INSTANCE",
            "sql_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "sql_username": "SQL_SA_USERNAME",
            "state": "present"
        }
    }
}
Read vars_file '../group_vars/all/vault'