diff --git a/lib/ansible/modules/windows/setup.ps1 b/lib/ansible/modules/windows/setup.ps1 index 22b94fc000..c6aa882b91 100644 --- a/lib/ansible/modules/windows/setup.ps1 +++ b/lib/ansible/modules/windows/setup.ps1 @@ -309,6 +309,13 @@ if($gather_subset.Contains('platform')) { $win32_os = Get-LazyCimInstance Win32_OperatingSystem $ip_props = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties() + try { + $ansible_reboot_pending = Get-PendingRebootStatus + } catch { + # fails for non-admin users, set to null in this case + $ansible_reboot_pending = $null + } + $ansible_facts += @{ ansible_architecture = $win32_os.OSArchitecture ansible_domain = $ip_props.DomainName @@ -320,7 +327,7 @@ if($gather_subset.Contains('platform')) { ansible_owner_contact = ([string] $win32_cs.PrimaryOwnerContact) ansible_owner_name = ([string] $win32_cs.PrimaryOwnerName) # FUTURE: should this live in its own subset? - ansible_reboot_pending = (Get-PendingRebootStatus) + ansible_reboot_pending = $ansible_reboot_pending ansible_system = $osversion.Platform.ToString() ansible_system_description = ([string] $win32_os.Description) ansible_system_vendor = $win32_cs.Manufacturer diff --git a/lib/ansible/modules/windows/win_iis_webbinding.ps1 b/lib/ansible/modules/windows/win_iis_webbinding.ps1 index 94d827f94e..5c479a1be0 100644 --- a/lib/ansible/modules/windows/win_iis_webbinding.ps1 +++ b/lib/ansible/modules/windows/win_iis_webbinding.ps1 @@ -365,6 +365,13 @@ ElseIf (-not $current_bindings -and $state -eq 'present') $result.changed = $true $result.operation_type = 'added' $result.website_state = (Get-Website | Where-Object {$_.Name -eq $Name}).State - $result.binding_info = Create-BindingInfo (Get-SingleWebBinding $binding_parameters) + + # incase there are no bindings we do a check before calling Create-BindingInfo + $web_binding = Get-SingleWebBinding $binding_parameters + if ($web_binding) { + $result.binding_info = Create-BindingInfo $web_binding + } else { + $result.binding_info = $null + } Exit-Json $result } diff --git a/lib/ansible/modules/windows/win_stat.ps1 b/lib/ansible/modules/windows/win_stat.ps1 index f44e9b848d..e7ffdd59ea 100644 --- a/lib/ansible/modules/windows/win_stat.ps1 +++ b/lib/ansible/modules/windows/win_stat.ps1 @@ -70,7 +70,13 @@ If ($info -ne $null) { # checksum = a file and get_checksum: True # md5 = a file and get_md5: True } - $stat.owner = $info.GetAccessControl().Owner + try { + $stat.owner = $info.GetAccessControl().Owner + } catch { + # may not have rights, historical behaviour was to just set to $null + # due to ErrorActionPreference being set to "Continue" + $stat.owner = $null + } # values that are set according to the type of file if ($info.Attributes.HasFlag([System.IO.FileAttributes]::Directory)) { diff --git a/test/integration/targets/win_route/files/Test-Os.ps1 b/test/integration/targets/win_route/files/Test-Os.ps1 deleted file mode 100644 index f91aa91c40..0000000000 --- a/test/integration/targets/win_route/files/Test-Os.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -$os = [Environment]::OSVersion -$major = $os.Version.Major -$minor = $os.Version.Minor -$ok = $false - -if(($major -gt 6)){ - $ok = $true -} -elseif (($major -eq 6) -and ($minor -ge 3)){ - $ok = $true -} - -$ok \ No newline at end of file diff --git a/test/integration/targets/win_route/tasks/main.yml b/test/integration/targets/win_route/tasks/main.yml index 79e1838b9a..b0f40dd06c 100644 --- a/test/integration/targets/win_route/tasks/main.yml +++ b/test/integration/targets/win_route/tasks/main.yml @@ -19,7 +19,7 @@ - name: get os info - script: ../files/Test-Os.ps1 + win_shell: '[Environment]::OSVersion.Version -ge [Version]"6.3"' register: os - name: Perform with os Windows 2012R2 or newer