-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Role Argument Spec Validation Improvements - String conversion, int ranges, Module validation features #77159
Comments
Files identified in the description: If these files are incorrect, please update the |
Generally speaking the intention of our argspec types is coercion validation. If you say the value requires an int, try to make it an int if possible, and fail otherwise. The same with
This was intentional, in that the MVP was only to implement certain aspects of the module argument spec functionality. Not that it cannot be extended at this point. |
Just as an FYI, the argument spec will never be able to implement every possible feature. For things like ranges, you would need to do what we recommend for plugin authors, and implement the check external to the argument spec. The argument spec would simply need to indicate it was an int, and then add an As for non-coercing validators, a |
There's another feature of module specs that doesn't appear to be supported in role specs: defaults. They can be specified, and |
roles already have a |
Sure, that's logical, but they don't quite serve the same purpose :-) |
@kpfleming see also #77664 |
Thanks for the link. This is definitely a complicated area, as I'd like to be able to set defaults for specific keys inside a |
This is partly related to #74995. |
Thank you very much for your submission to Ansible. It means a lot to us that you've taken time to contribute. Unfortunately, this issue has been open for some time while waiting for a contributor to take it up but there does not seem to have been anyone that did so. So we are going to close this issue to clear up the queues and make it easier for contributors to browse possible implementation targets. However, we're absolutely always up for discussion. Because this project is very active, we're unlikely to see comments made on closed tickets and we lock them after some time. If you or anyone else has any further questions, please let us know by using any of the communication methods listed in the page below: In the future, sometimes starting a discussion on the development list prior to proposing or implementing a feature can make getting things included a little easier, but it's not always necessary. Thank you once again for this and your interest in Ansible! |
Summary
(All code previews are from the
2.12.3
release commit on thestable-2.12
branch.)I was looking into valiadation methods for Ansible roles, and was excited to see that Ansible now has support for automatic role argument validation tasks through the
meta/argument_specs.yml
file.Only the 'options' portion of the argument specification is considered in the creation of automatically inserted validation tasks:
ansible/lib/ansible/playbook/role/__init__.py
Lines 350 to 365 in 0ee3815
Many features which are available to AnsibleModule's argument_spec are not available to role argument specifications, such as options being mutually exclusive, and I believe this may be why.
String conversion is another issue. The STRING_CONVERSION_ACTION configuration option appears to not apply here, and it appears that there is currently no way from within YAML (or existing code for that matter) to control whether or not things get converted to strings:
ansible/lib/ansible/module_utils/common/validation.py
Line 367 in 0ee3815
The only way strings are useful with this limitation in mind is to use the
choices
option for the spec and this is not applicable to every use case - even if it does support regular expressions.Lastly, range support for the
int
data type would be nice. For example, when you'd like to specify a valid port number and not have to use regex on a string to validate.The lack of these features is preventing me from using role argument spec validation within my roles versus other tools, particularly the default string conversion settings within the
check_type_str()
method. Being able to pass a list of dicts to my role when it expects a string and have it pass validation is something that I would like to be able to configure as a failure.Please let me know if this is better off as a proposal instead.
Issue Type
Feature Idea
Component Name
Role Argument Spec Validation
Additional Information
Ansible Version Info
Example Run
meta/argument_specs.yml
:test-playbook.yml
:tasks/main.yml
:ansible-playbook
run:Code of Conduct
The text was updated successfully, but these errors were encountered: