Skip to content

Commit

Permalink
Fix win_firewall bools comparation (ansible-collections#298)
Browse files Browse the repository at this point in the history
* fix gpoBoolean and Boolean comparation

fix gpoBoolean and Boolean comparation in windows 8.1 and win server 12r2 (with PS/WMF 4.x)

* append changelog

add changelog message about firewall bools comparation fix

* rename changelog fragment

rename changlog fragment (firewall... -> win_firewall)
  • Loading branch information
lydiym authored Sep 23, 2021
1 parent 926a399 commit 814c80c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- win_firewall - Fix GpoBoolean/Boolean comparation(windows versions compatibility increase)
10 changes: 6 additions & 4 deletions plugins/modules/win_firewall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ catch {
Fail-Json $result "win_firewall requires Get-NetFirewallProfile and Set-NetFirewallProfile Cmdlets."
}

$FIREWALL_ENABLED = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetSecurity.GpoBoolean]::True
$FIREWALL_DISABLED = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetSecurity.GpoBoolean]::False

Try {

ForEach ($profile in $firewall_profiles) {

$current_profile = Get-NetFirewallProfile -Name $profile
$currentstate = $current_profile.Enabled
$current_inboundaction = $current_profile.DefaultInboundAction
$current_outboundaction = $current_profile.DefaultOutboundAction
$result.$profile = @{
enabled = ($currentstate -eq 1)
enabled = ($currentstate -eq $FIREWALL_ENABLED)
considered = ($profiles -contains $profile)
currentstate = $currentstate
}
Expand All @@ -50,7 +52,7 @@ Try {

if ($state -eq 'enabled') {

if ($currentstate -eq $false) {
if ($currentstate -eq $FIREWALL_DISABLED) {
Set-NetFirewallProfile -name $profile -Enabled true -WhatIf:$check_mode
$result.changed = $true
$result.$profile.enabled = $true
Expand All @@ -71,7 +73,7 @@ Try {
}
} else {

if ($currentstate -eq $true) {
if ($currentstate -eq $FIREWALL_ENABLED) {
Set-NetFirewallProfile -name $profile -Enabled false -WhatIf:$check_mode
$result.changed = $true
$result.$profile.enabled = $false
Expand Down

0 comments on commit 814c80c

Please sign in to comment.