summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorShachafGoldstein <shachaf.gold@gmail.com>2019-06-25 23:19:59 +0300
committerMatt Davis <nitzmahone@users.noreply.github.com>2019-06-25 13:19:59 -0700
commit65b0e1425bbdc8e78f95f28396c3b58402803eac (patch)
treef34e0b7fb3304ee1253c51f7ebf26edbbd389ac5 /lib
parent5e2451c1a883c56c44cfe43397f2083c406a0513 (diff)
downloadansible-65b0e1425bbdc8e78f95f28396c3b58402803eac.tar.gz
win_pagefile - Fix idempotency when same settings as current (#57893)
* win_pagefile - Fix idempotency when same settings as current * Fix tests and code * Fix problem with system managed * Fix again systemmanaged detection * Change check of systemmanged in creation * Fix readability and wrong flag for test
Diffstat (limited to 'lib')
-rw-r--r--lib/ansible/modules/windows/win_pagefile.ps138
1 files changed, 37 insertions, 1 deletions
diff --git a/lib/ansible/modules/windows/win_pagefile.ps1 b/lib/ansible/modules/windows/win_pagefile.ps1
index c3a88d5a8e..610028a0e1 100644
--- a/lib/ansible/modules/windows/win_pagefile.ps1
+++ b/lib/ansible/modules/windows/win_pagefile.ps1
@@ -95,8 +95,10 @@ if ($state -eq "absent") {
Fail-Json $result "Unable to access '${drive}:' drive"
}
+ $curPagefile = Get-Pagefile $fullPath
+
# Set pagefile
- if ($null -eq (Get-Pagefile $fullPath)) {
+ if ($null -eq $curPagefile) {
try {
$pagefile = Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{name = $fullPath; InitialSize = 0; MaximumSize = 0} -WhatIf:$check_mode
} catch {
@@ -129,6 +131,40 @@ if ($state -eq "absent") {
}
}
$result.changed = $true
+ }else
+ {
+ $CurPageFileSystemManaged = (Get-CimInstance -ClassName win32_Pagefile -Property 'System' -Filter "name='$($fullPath.Replace('\','\\'))'").System
+ if ((-not $check_mode) -and
+ -not ($systemManaged -or $CurPageFileSystemManaged) -and
+ ( ($curPagefile.InitialSize -ne $initialSize) -or
+ ($curPagefile.maximumSize -ne $maximumSize)))
+ {
+ $curPagefile.InitialSize = $initialSize
+ $curPagefile.MaximumSize = $maximumSize
+ try {
+ $curPagefile.Put() | out-null
+ } catch {
+ $originalExceptionMessage = $($_.Exception.Message)
+ # Try workaround before failing
+ try {
+ Remove-Pagefile $fullPath -whatif:$check_mode
+ } catch {
+ Fail-Json $result "Failed to remove pagefile before workaround $($_.Exception.Message) Original exception: $originalExceptionMessage"
+ }
+ try {
+ $pagingFilesValues = (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management").PagingFiles
+ } catch {
+ Fail-Json $result "Failed to get pagefile settings from the registry for workaround $($_.Exception.Message) Original exception: $originalExceptionMessage"
+ }
+ $pagingFilesValues += "$fullPath $initialSize $maximumSize"
+ try {
+ Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" "PagingFiles" $pagingFilesValues
+ } catch {
+ Fail-Json $result "Failed to set pagefile settings to the registry for workaround $($_.Exception.Message) Original exception: $originalExceptionMessage"
+ }
+ }
+ $result.changed = $true
+ }
}
} elseif ($state -eq "query") {
$result.pagefiles = @()