You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When validating argument_spec with entry that is type='list', elements='int' and choices set to be list of ints, it fails to show proper validation error if value is not within choices. Just to be clear, validation works, just module crashes because can't format message. If value is within choices range, then there is no error.
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t allCOLLECTIONS_PATHS(/***/ansible.cfg) = ['***']CONFIG_FILE() = /***/ansible.cfgEDITOR(env: EDITOR) = vim
{"failed": true, "msg": "value of foo must be one or more of: 1. Got no match for: 2", "invocation": {"module_args": {"foo": [2]}}}
Actual Results
Traceback (most recent call last): File "/***/ansible_collections/***/plugins/module_utils/example.py", line 22, in <module> main() File "/***/ansible_collections/***/plugins/module_utils/example.py", line 18, in main run_module() File "/***/ansible_collections/***/plugins/module_utils/example.py", line 11, in run_module module = basic.AnsibleModule(argument_spec=module_args, supports_check_mode=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/***/.venv/lib64/python3.11/site-packages/ansible/module_utils/basic.py", line 488, in __init__ self.validation_result = self.validator.validate(self.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/***/.venv/lib64/python3.11/site-packages/ansible/module_utils/common/arg_spec.py", line 301, in validate result = super(ModuleArgumentSpecValidator, self).validate(parameters) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/***/.venv/lib64/python3.11/site-packages/ansible/module_utils/common/arg_spec.py", line 241, in validate _validate_argument_values(self.argument_spec, result._validated_parameters, errors=result.errors) File "/***/.venv/lib64/python3.11/site-packages/ansible/module_utils/common/parameters.py", line 666, in _validate_argument_values diff_str = ", ".join(diff_list) ^^^^^^^^^^^^^^^^^^^^TypeError: sequence item 0: expected str instance, int found
Code of Conduct
I agree to follow the Ansible Code of Conduct
The text was updated successfully, but these errors were encountered:
* Handle error raised when argument validation with elements=int
and value is not within choices
Fixes: ansible#82776
Signed-off-by: Abhijeet Kasurde <[email protected]>
* Handle error raised when argument validation with elements=int
and value is not within choices
Fixes: #82776
Signed-off-by: Abhijeet Kasurde <[email protected]>
bcoca
pushed a commit
to bcoca/ansible
that referenced
this issue
Mar 19, 2024
* Handle error raised when argument validation with elements=int
and value is not within choices
Fixes: ansible#82776
Signed-off-by: Abhijeet Kasurde <[email protected]>
Summary
When validating
argument_spec
with entry that istype='list'
,elements='int'
andchoices
set to be list of ints, it fails to show proper validation error if value is not withinchoices
. Just to be clear, validation works, just module crashes because can't format message. If value is withinchoices
range, then there is no error.Issue Type
Bug Report
Component Name
lib/ansible/module_utils/common/parameters.py
Ansible Version
Configuration
OS / Environment
RHEL8
Steps to Reproduce
Expected Results
Actual Results
Code of Conduct
The text was updated successfully, but these errors were encountered: