Comments (3)
Integer options in Ansible have traditionally always been a signed integer [Int32]
so any values that exceed 2147483647
have to be represented as a negative as the leading bit is whether it is a negative or not. In your case this is -1073741819
which you can derive from:
[Int32]("0x{0:X}" -f ([uint32]3221225477))
So technically you should be able to do expected_return_code: [0, 3010, -1073741819]
to achieve the behaviour you want.
Unfortunately when testing this with the following playbook I've encounted another issue that stops it from working.
- hosts: '2019'
gather_facts: no
tasks:
- ansible.windows.win_package:
path: C:\Windows\System32\cmd.exe
arguments: /c exit 4294967295 # cmd seems to accept a signed and unsigned integer here
expected_return_code:
- 0
- -1
state: present
product_id: not here
The problem is that the code that is returning the exit code back to win_package
is returning it as a UInt32
so when we check to see if the rc is in the expected_return_code
we don't get a match between the signed and unsigned variant. We have a few possible solutions here
- Change
win_package
to parseexpected_return_code
as a list of unsigned integers- This could be a breaking change if anybody is passing in a negative already but as we can see it doesn't do anything right now
- It is technically a departure from our normal standard of using signed integers for fields
- Change the
Ansible.ModuleUtils.CommandUtil
to return the rc as a signed integer- Aligns more of our codebase to use signed integers but has the potential to break a module that is relying on this being an unsigned int
- I don't think anything in our codebase has that expectation but 3rd party modules might
- Do an explicit conversion in
win_package
to convert the rc from CommandUtil to the signed variant and compare- This is the least obtrusive change as it only affects this part of win_package
- Keeps things as an int32 which seems to be the standard in both Ansible and PowerShell,
$LASTEXITCODE
is an int32 - Would probably need to change the
rc
return value to be a signed number to avoid any confusion
A fourth option could be a combination of the 2 and have the int
field in Ansible a bit more dynamically defined. What I mean is that it will still be an Int32
in PowerShell once parsed but it tries to first parse the signed variant -2147483648 to 2147483647
and if it exceeds 2147483647
it will parse it as a UInt32
then convert to Int32
using the same byte value, i.e. 4294967295
becomes -1
.
from ansible.windows.
I ended up going to option 3 as that was the least obtrusive change required. The PR that implements this fix is #47.
from ansible.windows.
Thanks for mentioning the possible workaround of using the negative... I had thought of and tried that, and noticed the same problem you noted.
Thanks for preparing the PR!
from ansible.windows.
Related Issues (20)
- win_get_url does not respect content-disposition HOT 1
- win_update failed since ansible 7.7.0 HOT 3
- win_update show different trigger in Event Viewer HOT 1
- ansible.windows.win_powershell misinterprets block scalar (string block) HOT 2
- win_package: support checksum verification HOT 2
- intermittent winrm connection failures with large hosts count HOT 8
- intermittent "unable to delete temporary file" errors HOT 9
- Win_updates fail with "Exception from HRESULT: 0x80072EE2" HOT 2
- Windows Update Module not installing any updates HOT 4
- Windows update failes due to update loop HOT 3
- win_environment : Maybe add an option to read variable content ? HOT 5
- Error during machine sid retrieval: An error (1788) occurred while enumerating the group membership. The member's SID could not be resolved. HOT 8
- Access denied after renaming windows host : Server not found in Kerberos database HOT 10
- Failed to create temporary directory when running win_template module against Windows Server 2019 HOT 10
- win_copy doesnt work when folder name has special character HOT 2
- Add account_expires functionality from the Set-LocalUser PowerShell Cmdlet HOT 2
- Using Machine credentials from AAP passed to playbook with ansible.windows.win_copy fails HOT 2
- ERROR DURING WINRM SEND INPUT - attempting to recover: WinRMTransportError Bad HTTP response returned from server. Code 413 HOT 1
- win_copy module not handling an invalid path correctly. HOT 1
- Feature request: A better win_acl module HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansible.windows.