ansible-collections / community.windows

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

Fix Physical Path changing on modules/win_iis_webapplication.ps1 #385

Closed AbianG closed 2 years ago

AbianG commented 2 years ago

Remove Get-Item for current application physical path to prevent errors if current path does not exist. Update comparison to use the physical path value already stored in the $application variable.

SUMMARY

When using win_iis_webapplication under certain conditions the underliying powershell code will produce an irrecoverable error. Premise: If the currently set physicalPath does not exist, the execution of the module will fail with the error Cannot find path '$path' because it does not exist.

The existing path should not be validated, as this module may be run exactly to update a webApp that is broken due to a missing/modified PhysicalPath. The only path that should be validated (and it is) is the new physical path to be set.

This PR aims to improve the way the module behaves by removing the implicit check that is induced by using Get-Item to evaluate the currently set physicalPath, which is then treated as a LiteralPath to be compared as a string with the value of the new path to be set.

With this change, the paths are still compared and only changed if they differ, but the implicit validation for the currently set path is removed, preventing the module from throwing and error when it has been modified or does no longer exist. The path to be set is already validated on Line 77

ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION

How to reproduce the issue: