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

[Request] Provide a way to avoid resetting login passwords if login exists. #192

Closed OsirisDBA closed 7 months ago

OsirisDBA commented 1 year ago

As part of my company's infrastructure-as-code initiative I'm trying to generate a host_vars file that contains all items on the instance. One of the problems I've noticed relates to user logins. I'm utilizing a list of dictionaries structure to describe the logins

sqlserver_cluster_logins:
  - login: SomeServiceAccount
    password: <lookup>
    password_must_change: false
    password_policy_enforced: true
    password_expiration_enabled: false
    enabled: true

  - login: SomeUserAccount
    password: <generated generic default>
    password_must_change: true
    password_policy_enforced: true
    password_expiration_enabled: true
    enabled: true

For these user accounts I don't want to reset the password if the account already exists. Yet I won't know if this is a new account or and existing account until inside the login module.

One solution I've considered is adding a new parameter to the login module such as skip_password_reset: (true|false) that would ignore the password parameter if the login already exists.

Otherwise, I'll need to fallback to using win_powershell and calling Get-DbaLogin/Set-DbaLogin/Remove-DbaLogin myself.

It's simple to implement but I'd like to hear your thoughts on the issue.

OsirisDBA commented 1 year ago

One potential solution: https://github.com/OsirisDBA/lowlydba.sqlserver/commit/78688a71a9eb581339bbc9da437f5efdfcbb6614

lowlydba commented 1 year ago

Hey, thanks for the suggestion! I vaguely recall there being a blocker to implementing this when I wrote it, but that was a long time ago and pre v2 of dbatools, so maybe its not an issue anymore 🤔

That approach looks fine by me, feel free to open a PR for it and we can review/test!