diff --git a/lib/ansible/modules/extras/windows/win_iis_webapppool.ps1 b/lib/ansible/modules/extras/windows/win_iis_webapppool.ps1 index 858a151f2a3..4172dc2f336 100644 --- a/lib/ansible/modules/extras/windows/win_iis_webapppool.ps1 +++ b/lib/ansible/modules/extras/windows/win_iis_webapppool.ps1 @@ -90,10 +90,18 @@ try { Stop-WebAppPool -Name $name -ErrorAction Stop $result.changed = $TRUE } - if ((($state -eq 'started') -and ($pool.State -eq 'Stopped')) -or ($state -eq 'restarted')) { + if ((($state -eq 'started') -and ($pool.State -eq 'Stopped'))) { Start-WebAppPool -Name $name -ErrorAction Stop $result.changed = $TRUE } + if ($state -eq 'restarted') { + switch ($pool.State) + { + 'Stopped' { Start-WebAppPool -Name $name -ErrorAction Stop } + default { Restart-WebAppPool -Name $name -ErrorAction Stop } + } + $result.changed = $TRUE + } } } catch { Fail-Json $result $_.Exception.Message @@ -112,4 +120,4 @@ if ($pool) $pool.Attributes | ForEach { $result.info.attributes.Add($_.Name, $_.Value)}; } -Exit-Json $result +Exit-Json $result \ No newline at end of file