Closed PfurtschellerP closed 1 year ago
After experimenting a bit with the module I think I found the cause. $existing_rule.ApplicationName
can't be set to $null
(which seems to be required for it to really be set to any).
I added the following to lines:
Variable Conversion around line 170
if ($null -ne $program -and $program -ne "any") {
$new_rule.ApplicationName = [System.Environment]::ExpandEnvironmentVariables($program)
} elseif ($program -eq "any") {
$new_rule.ApplicationName = $program
}
Parameter assignment around line 275
If ($prop -eq 'Profiles') {
$existingRule.Profiles = [int] $new_rule.$prop
}
# If Application Name is "any" the value of the firewall rule has to be $null, so must use Set-NetFirewallRule here.
ElseIf(($prop -eq 'ApplicationName') -and ($new_rule.$prop -eq "any")) {
Set-NetFirewallRule -DisplayName "$($existingRule.Name)" -Program "any"
}
Else {
$existingRule.$prop = $new_rule.$prop
}
I am not an experienced Powershell user but this seems to fix this issue. I created a draft PR here https://github.com/ansible-collections/community.windows/pull/472
SUMMARY
When using the
win_firewall_rule module
and having set program toany
the module fails with the following message:ISSUE TYPE
COMPONENT NAME
win_firewall_rule
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
Ansible execution from Debian 11 and AWX/RHEL8.6. Target system is Windows Server 2019 Standard
STEPS TO REPRODUCE
EXPECTED RESULTS
The program attribute of the firewall rule should change to any.
ACTUAL RESULTS
The modules fails.