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
20 stars 12 forks source link

[Bug] ag_listener always calling Set-DbaAgListener if listener exists #206

Closed OsirisDBA closed 1 year ago

OsirisDBA commented 1 year ago

Describe the bug When calling ag_listener on an existing listener with state = present and matching port numbers, an error is thrown by Set-DbaAgListener

The listener with DNS name 'mylistener' for the availability group 'myAG' is already listening on the TCP port 1433. Please choose a different TCP port for the listener. If there is a problem with the listener, try restarting the listener to correct the problem.

Expected behavior When calling ag_listener on an existing listener with state = present and matching port numbers, I expect no action to be taken.

Dbatools : 2.0.4

The issue is that Get-DbaAgListener uses the keyname PortNumber for the listener port while Set-DbaAgListener uses Port. The ag_listener module uses Port for both so the not equals comparison is always true.

lowlydba/sqlserver/plugins/modules/ag_listener.ps1

        elseif ($existingListener.Port -ne $port) {
            Set-DbaAgListener -AvailabilityGroup $agName -Listener $listenerName -Port $port
            $module.Result.changed = $true
        }

should be

        elseif ($existingListener.PortNumber -ne $port) {
            Set-DbaAgListener -AvailabilityGroup $agName -Listener $listenerName -Port $port
            $module.Result.changed = $true
        }
lowlydba commented 1 year ago

Thanks for reporting this! I don't have a ton of time to allocate to this project right now, but am happy to take a PR with this small fix.