Skip to content

Create JSON schemas for various inventory data structuresΒ #217

Description

@sk4zuzu

Complex inventory structures like pci_devices, ovs or gate_tproxy could use some JSON schema pre-checks. TProxy config for instance is validated in precheck role

- name: Ensure input TProxy config is correctly structured
ansible.builtin.assert:
that: "{{ 0 == (_loop[item].query | flatten | count) }}"
fail_msg: "{{ _loop[item].msg }}: {{ _loop[item].query | to_json }}"
loop: "{{ range(_loop | count) | list }}"
vars:
_required: [":service_port", ":remote_addr", ":remote_port"]
_optional: [":networks"]
_loop:
# Look for missing keys.
- query: >-
{{ gate_tproxy | map('dict2items')
| map('map', attribute='key')
| map('symmetric_difference', _required)
| map('intersect', _required) }}
msg: "Missing keys detected"
# Look for unknown keys.
- query: >-
{{ gate_tproxy | map('dict2items')
| map('map', attribute='key')
| map('difference', _required + _optional) }}
msg: "Unknown keys detected"
# Look for empty (invalid) values.
- query: >-
{{ gate_tproxy | map('dict2items')
| map('selectattr', 'key', 'in', _required)
| map('selectattr', 'value', 'falsy')
| map('map', attribute='key') }}
msg: "Empty values detected"
when:
- gate_tproxy is defined
- gate_tproxy is sequence
run_once: true
but introducing a less "ad-hoc" approach seems to be a nice idea. πŸ‘ πŸ˜‡

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions