File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ trivial :
3+ - " Fixes unit tests execution by updating set_module_args to automatically patch module arguments using the new patch_module_args for ansible 2.19"
Original file line number Diff line number Diff line change 1111from ansible .module_utils ._text import to_bytes
1212
1313
14+ cur_context = None
15+
16+
1417def set_module_args (args ):
18+ global cur_context
19+
20+ # Add common defaults
1521 if "_ansible_remote_tmp" not in args :
1622 args ["_ansible_remote_tmp" ] = "/tmp"
1723 if "_ansible_keep_remote_files" not in args :
1824 args ["_ansible_keep_remote_files" ] = False
1925
20- args = json .dumps ({"ANSIBLE_MODULE_ARGS" : args })
21- basic ._ANSIBLE_ARGS = to_bytes (args )
26+ # Clean up any previous context manager if it exists
27+ if cur_context is not None :
28+ try :
29+ cur_context .__exit__ (None , None , None )
30+ except Exception :
31+ pass
32+ cur_context = None
33+
34+ # Try to use the newer patch_module_args
35+ try :
36+ from ansible .module_utils .testing import patch_module_args
37+
38+ cur_context = patch_module_args (args )
39+ cur_context .__enter__ ()
40+ except ImportError :
41+ # Fall back to original behavior for older Ansible versions
42+ serialized_args = json .dumps ({"ANSIBLE_MODULE_ARGS" : args })
43+ basic ._ANSIBLE_ARGS = to_bytes (serialized_args )
2244
2345
2446class AnsibleExitJson (Exception ):
You can’t perform that action at this time.
0 commit comments