From 2a27176d7c5e7a9216b569a24579a214aa2a2cee Mon Sep 17 00:00:00 2001 From: JimFicarra Date: Thu, 26 Jan 2017 19:32:49 -0500 Subject: [PATCH] Add feature - win_package - allow non-zero return codes - Issue #20408 (#20410) --- lib/ansible/modules/windows/win_package.ps1 | 1 + lib/ansible/modules/windows/win_package.py | 26 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/ansible/modules/windows/win_package.ps1 b/lib/ansible/modules/windows/win_package.ps1 index fd161dd9866..5d4a14ab0dd 100644 --- a/lib/ansible/modules/windows/win_package.ps1 +++ b/lib/ansible/modules/windows/win_package.ps1 @@ -850,6 +850,7 @@ function Set-TargetResource if($process) { $exitCode = $process.ExitCode + Set-Attr -obj $result -name "exit_code" -value $exitCode } } } diff --git a/lib/ansible/modules/windows/win_package.py b/lib/ansible/modules/windows/win_package.py index b20e1c4a47c..bea20fe6758 100644 --- a/lib/ansible/modules/windows/win_package.py +++ b/lib/ansible/modules/windows/win_package.py @@ -74,6 +74,12 @@ options: - Password of an account with access to the package if it's located on a file share. Only needed if the winrm user doesn't have access to the package. Also specify user_name for this to function properly. default: null required: false + expected_return_code: + description: + - One or more return codes from the package installation that indicates success. + - If not provided, defaults to 0 + required: no + default: 0 ''' EXAMPLES = r''' @@ -94,4 +100,24 @@ EXAMPLES = r''' path: https://download.microsoft.com/download/A/F/0/AF0071F3-B198-4A35-AA90-C68D103BDCCF/rdcman.msi product_id: '{0240359E-6A4C-4884-9E94-B397A02D893C}' state: absent + +# Specify the expected non-zero return code when successful +# In this case 3010 indicates 'reboot required' +- name: 'Microsoft .NET Framework 4.5.1' + win_package: + path: https://download.microsoft.com/download/1/6/7/167F0D79-9317-48AE-AEDB-17120579F8E2/NDP451-KB2858728-x86-x64-AllOS-ENU.exe + productid: '{7DEBE4EB-6B40-3766-BB35-5CBBC385DA37}' + arguments: '/q /norestart' + ensure: present + expected_return_code: 3010 + +# Specify multiple non-zero return codes when successful +# In this case we can say that both 0 (SUCCESSFUL) and 3010 (REBOOT REQUIRED) codes are acceptable + - name: 'Microsoft .NET Framework 4.5.1' + win_package: + path: https://download.microsoft.com/download/1/6/7/167F0D79-9317-48AE-AEDB-17120579F8E2/NDP451-KB2858728-x86-x64-AllOS-ENU.exe + productid: '{7DEBE4EB-6B40-3766-BB35-5CBBC385DA37}' + arguments: '/q /norestart' + ensure: present + expected_return_code: [0,3010] '''