Validation fails when parent role has no variable in inventory
Given the following playbook:
---
- name: test
hosts: localhost
gather_facts: true
roles:
- role: foobar
tags:
- foobar
Role foobar
has foobar_variable_schema
set with:
# tasks/main.yaml
---
- name: Import_role | validate role parameters
ansible.builtin.import_role:
name: validate_role_parameters
# vars/main.yaml
---
foobar_variable_schema:
$schema: https://json-schema.org/draft-07/schema
type: object
properties:
foobar_string:
type: string
required:
- foobar_string
If foobar_string
has no default value and is not set in inventory, task Validate | ensure role variables are properly defined
fails:
TASK [validate_role_parameters : Validate | ensure role variables are properly defined] *******
fatal: [localhost]: FAILED! =>
msg: |-
The task includes an option with an undefined variable. The error was: 'validate_role_parameter_parent_variable' is undefined. 'validate_role_parameter_parent_variable' is undefined
The error appears to be in '/SOME_PATH/role/validate_role_parameters/tasks/validate.yaml': line 35, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Validate | ensure role variables are properly defined
^ here