Repository navigation
[Bug] Tasks using login module keeps returning changed true even when login already present #409
|
Describe the bug 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: presentExpected behavior Versions:
Additional context |
Replies: 5 comments
|
This is an intentional thing right now, since it isn't easy to detect if we've actually changed a login's password or not. If you have a suggestion for a better implementation, I would accept a PR for it. |
|
I'm going to close this in the mean time since the functionality is intended. |
|
Sorry for the delay in my own reply. I do realize now that dealing with passwords and idempotency is tricky. I moved on to some other topics and haven't got the time to play around with DBAtools, but I'm curious about the return value PasswordChanged that we can see in the output log that I posted. I suspect that this flag return value should be "false" if i run the task again with the same login/password that I first used upon creation. I'll try to test this tomorrow. And this is off topic about current issue. But THANKS a lot for this sqlserver Ansible collection. Your "nonquery" module has helped me SO much! |
|
Hm, sorry I may have missed the "PasswordChanged" initially. I want to say that that field wasn't present in DBATools when I first wrote this, but if they're already handling that upstream then it should be easy to use that data versus implementing the logic in this collection. I'll take another look. |
|
It seems upstream they also can only infer if the pass has changed, so I don't think using the PassswordChanged value will actually be a different functionality: A workaround may be to "create" the login with a task in check mode first, then depending on if it exists or not, followup with a task to create the login (including password) or modify the login (not including password, or using skip_reset). Or, another route would be to use a nonquery with T-SQL to ensure the login simply exists & has the desired password, then perform all the other config using a login task, removing the need to specify the password to the task. That may be as close as we can get unfortunately. |
It seems upstream they also can only infer if the pass has changed, so I don't think using the PassswordChanged value will actually be a different functionality:
https://github.com/dataplat/dbatools/blob/918182a32f96c20ee9fa28a7a6ede2a48eba233f/public/Set-DbaLogin.ps1#L432-L433
A workaround may be to "create" the login with a task in check mode first, then depending on if it exists or not, followup with a task to create the login (including password) or modify the login (not including password, or using skip_reset).
Or, another route would be to use a nonquery with T-SQL to ensure the login simply exists & has the desired password, then perform all the other config using a login task, rem…