lowlydba.sqlserver icon indicating copy to clipboard operation
lowlydba.sqlserver copied to clipboard

[Bug] lowlydba.sqlserver.ag_listener module - fails to create a multi-subnet listener

Open daarrn opened this issue 1 month ago • 1 comments

Describe the bug when creating a multi-subnet AG listener you are required to pass in a comma separated list of IP addresses to the ip_address parameter, however the ip_address parameter is being handled as a type = 'str' in https://github.com/lowlydba/lowlydba.sqlserver/blob/main/plugins/modules/ag_listener.ps1

this causes any comma separated list passed to the ip_address parameter to be treated as a whole single string.

ex: ip_address: 10.10.10.1, 10.10.11.1

what get's passed to the underlying dbatools function, add-dbaaglistener, is a string value that looks like "10.10.10.1, 10.10.11.1" which returns an error "...invalid IP address..."

To Reproduce

lowlydba.sqlserver.ag_listener: ag_name: "some_ag_name" ip_address: 10.10.10.1, 10.10.11.1 listener_name: "some_listener_name" sql_instance: "some_sql_instance"

you will receive the following output

37│ msg: 'Configuring availability group listener failed: Cannot process argument transformation 38│ on parameter ''IPAddress''. Cannot convert value "10.10.10.1,10.10.11.1" 39│ to type "System.Net.IPAddress[]". Error: "Cannot convert value "10.10.10.1,10.10.11.1" 40│ to type "System.Net.IPAddress". Error: "An invalid IP address was specified.""'

in our case the IP address were being passed to this module as ansible variables

lowlydba.sqlserver.ag_listener: ag_name: "some_ag_name" ip_address: '{{ primary_ip }},{{ secondary_ip }}' listener_name: "some_listener_name" sql_instance: "some_sql_instance"

Expected behavior we expected this to create a multi subnet AG listener utilizing both IP addresses

Versions(please complete the following information):

  • OS: windows server 2019
  • SQL Server: 2022
  • PowerShell: 5.1.17763.3770

Additional context I validated that changing line 18 of ag_listener.ps1 to accept a list instead of a string fixes this issue https://github.com/lowlydba/lowlydba.sqlserver/blob/main/plugins/modules/ag_listener.ps1

$spec = @{ supports_check_mode = $true options = @{ ag_name = @{type = 'str'; required = $true } listener_name = @{type = 'str'; required = $true } ip_address = @{type = 'list'; required = $false } subnet_ip = @{type = 'str'; required = $false } subnet_mask = @{type = 'str'; required = $false; default = '255.255.255.0' } port = @{type = 'int'; required = $false; default = 1433 } dhcp = @{type = 'bool'; required = $false; default = $false } state = @{type = "str"; required = $false; default = "present"; choices = @("present", "absent") } } }

the change does require that when sending multiple IP address to the module that you send a valid list parameter

ex:

lowlydba.sqlserver.ag_listener: ag_name: "some_ag_name" ip_address: - 10.10.10.1 - 10.10.11.1 listener_name: "some_listener_name" sql_instance: "some_sql_instance"

daarrn avatar May 07 '24 21:05 daarrn