ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
199 stars 153 forks source link

Casting error on web_iis_website with parameters of type != String #437

Open Clebam opened 2 years ago

Clebam commented 2 years ago
SUMMARY

When setting a parameter that needs a non string value, there is a an error that is thrown : "Specified cast is not valid."

ISSUE TYPE
COMPONENT NAME

Module : win_iis_website Parameter: parameters Code : https://github.com/ansible-collections/community.windows/blob/main/plugins/modules/win_iis_website.ps1#L138

ANSIBLE VERSION

N/A

COLLECTION VERSION

N/A

CONFIGURATION

N/A

OS / ENVIRONMENT

Windows Server 2016 and above

STEPS TO REPRODUCE
- name: Acme IIS site
  community.windows.win_iis_website:
    name: Acme
    parameters: limits.maxBandwidth:10000
EXPECTED RESULTS

limits.maxBandwidth should have a value of 10000

ACTUAL RESULTS

Specified cast is not valid.

Possible Workaround

From here : https://github.com/ansible-collections/community.windows/blob/main/plugins/modules/win_iis_website.ps1#L138

$cast_type = $property_value.TypeName
$casted_value = $_[1] -as $cast_type

if ((-not $parameter_value) -or ($parameter_value) -ne $casted_value) {
    Set-ItemProperty -LiteralPath "IIS:\Sites\$($site.Name)" $_[0] $casted_value
    $result.changed = $true
}

Thanks