New release of capable.core212 collection - 1.2.0.
There is new action plugin to validate variable values:
https://capable-core.github.io/collections/capable/core212/modules/validate_vars/
Unfortunately there is ongoing issue with how plugin documentation is rendered on galaxy. So no documentation there. I am working on proper modern documentation website for capable project.
Briefly main differences to already existing ansible.builtin.validate_argument_spec
- Strict types - int, str and types that allow coercion - str_int, str_bool
- Custom validation conditions with this keyword
- capable.core212.validate_vars:
custom_validation_username:
type: str
required: true
custom_validation:
- condition: **this** | length >= 5
error_message: "Username must be at least 5 characters long."
- condition: **this** is match('^[a-z]+$')
error_message: "Username must contain only lowercase letters."
custom_validation_score:
type: int
custom_validation:
- condition: **this** >= 0 and **this** <= 100
error_message: "Score must be between 0 and 100."
vars:
custom_validation_username: "alicea"
custom_validation_score: 85
mutually_exclusive,required_together,required_one_of,required_if,required_bybut for ansible variables (not module arguments)
for example:
- capable.core212.validate_vars:
ri_state: {type: str}
ri_name: {type: str}
ri_path: {type: str}
required_if:
- ['ri_state', 'present', ['ri_name', 'ri_path']]
vars:
ri_state: "present"
ri_name: "alpha"
ri_path: "/tmp/alpha"
As this is in core212 collection, works on all ansible-core versions starting from 2.12.