win_dotnet_ngen: fix after broken in 2.4 (#31076)

* win_dotnet_ngen: fix after broken in 2.4

* added description to return values

(cherry picked from commit 12a4dca447)
pull/31222/head
Jordan Borean 7 years ago committed by jborean93
parent 2513078f39
commit 737a0d6015

@ -1,71 +1,62 @@
#!powershell #!powershell
# This file is part of Ansible # This file is part of Ansible
#
# Copyright 2015, Peter Mounce <public@neverrunwithscissors.com> # Copyright 2015, Peter Mounce <public@neverrunwithscissors.com>
# # Copyright (c) 2017 Ansible Project
# Ansible is free software: you can redistribute it and/or modify # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
$ErrorActionPreference = "Stop" #Requires -Module Ansible.ModuleUtils.Legacy.psm1
#Requires -Module Ansible.ModuleUtils.CommandUtil.psm1
# WANT_JSON $ErrorActionPreference = 'Stop'
# POWERSHELL_COMMON
$params = Parse-Args $args; $params = Parse-Args $args -supports_check_mode $true
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
$result = @{ $result = @{
changed = $false changed = $false
} }
function Invoke-NGen Function Invoke-Ngen($architecture="") {
{ $cmd = "$($env:windir)\Microsoft.NET\Framework$($architecture)\v4.0.30319\ngen.exe"
[CmdletBinding()]
if (Test-Path -Path $cmd) {
param $arguments = "update /force"
( if ($check_mode) {
[Parameter(Mandatory=$false, Position=0)] [string] $arity = "" $ngen_result = @{
) rc = 0
stdout = "check mode output for $cmd $arguments"
if ($arity -eq $null) }
{ } else {
$arity = "" try {
} $ngen_result = Run-Command -command "$cmd $arguments"
$cmd = "$($env:windir)\microsoft.net\framework$($arity)\v4.0.30319\ngen.exe" } catch {
if (test-path $cmd) Fail-Json -obj $result -message "failed to execute '$cmd $arguments': $($_.Exception.Message)"
{ }
$update = Invoke-Expression "$cmd update /force"; }
$(result.dotnet_ngen$($arity)_update_exit_code) = $lastexitcode $result."dotnet_ngen$($architecture)_update_exit_code" = $ngen_result.rc
$(result.dotnet_ngen$($arity)_update_output) = $update $result."dotnet_ngen$($architecture)_update_output" = $ngen_result.stdout
$eqi = Invoke-Expression "$cmd executequeueditems";
$(result.dotnet_ngen$($arity)_eqi_exit_code) = $lastexitcode $arguments = "executeQueuedItems"
$(result.dotnet_ngen$($arity)_eqi_output) = $eqi if ($check_mode) {
$executed_queued_items = @{
rc = 0
stdout = "check mode output for $cmd $arguments"
}
} else {
try {
$executed_queued_items = Run-Command -command "$cmd $arguments"
} catch {
Fail-Json -obj $result -message "failed to execute '$cmd $arguments': $($_.Exception.Message)"
}
}
$result."dotnet_ngen$($architecture)_eqi_exit_code" = $executed_queued_items.rc
$result."dotnet_ngen$($architecture)_eqi_output" = $executed_queued_items.stdout
$result.changed = $true $result.changed = $true
} }
else
{
Write-Host "Not found: $cmd"
}
} }
Try Invoke-Ngen
{ Invoke-Ngen -architecture "64"
Invoke-NGen
Invoke-NGen -arity "64"
Exit-Json $result; Exit-Json -obj $result
}
Catch
{
Fail-Json $result $_.Exception.Message
}

@ -45,6 +45,57 @@ options: {}
''' '''
EXAMPLES = r''' EXAMPLES = r'''
# Run ngen tasks - name: run ngen tasks
win_dotnet_ngen: win_dotnet_ngen:
''' '''
RETURN = r'''
dotnet_ngen_update_exit_code:
description: The exit code after running the 32-bit ngen.exe update /force
command.
returned: 32-bit ngen executable exists
type: int
sample: 0
dotnet_ngen_update_output:
description: The stdout after running the 32-bit ngen.exe update /force
command.
returned: 32-bit ngen executable exists
type: str
sample: sample output
dotnet_ngen_eqi_exit_code:
description: The exit code after running the 32-bit ngen.exe
executeQueuedItems command.
returned: 32-bit ngen executable exists
type: int
sample: 0
dotnet_ngen_eqi_output:
description: The stdout after running the 32-bit ngen.exe executeQueuedItems
command.
returned: 32-bit ngen executable exists
type: str
sample: sample output
dotnet_ngen64_update_exit_code:
description: The exit code after running the 64-bit ngen.exe update /force
command.
returned: 64-bit ngen executable exists
type: int
sample: 0
dotnet_ngen64_update_output:
description: The stdout after running the 64-bit ngen.exe update /force
command.
returned: 64-bit ngen executable exists
type: str
sample: sample output
dotnet_ngen64_eqi_exit_code:
description: The exit code after running the 64-bit ngen.exe
executeQueuedItems command.
returned: 64-bit ngen executable exists
type: int
sample: 0
dotnet_ngen64_eqi_output:
description: The stdout after running the 64-bit ngen.exe executeQueuedItems
command.
returned: 64-bit ngen executable exists
type: str
sample: sample output
'''

@ -0,0 +1,20 @@
# this only tests check mode as the full run can take several minutes to
# complete, this way we at least verify the script is parsable
---
- name: run in check mode
win_dotnet_ngen:
register: result_check
check_mode: yes
- name: assert run in check mode
assert:
that:
- result_check|changed
- result_check.dotnet_ngen_update_exit_code == 0
- result_check.dotnet_ngen_update_output == "check mode output for C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\ngen.exe update /force"
- result_check.dotnet_ngen_eqi_exit_code == 0
- result_check.dotnet_ngen_eqi_output == "check mode output for C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\ngen.exe executeQueuedItems"
- result_check.dotnet_ngen64_update_exit_code == 0
- result_check.dotnet_ngen64_update_output == "check mode output for C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\ngen.exe update /force"
- result_check.dotnet_ngen64_eqi_exit_code == 0
- result_check.dotnet_ngen64_eqi_output == "check mode output for C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\ngen.exe executeQueuedItems"
Loading…
Cancel
Save