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. π π
Complex inventory structures like
pci_devices,ovsorgate_tproxycould use some JSON schema pre-checks. TProxy config for instance is validated in precheck roleone-deploy/roles/precheck/pre_reboot/tasks/tproxy.yml
Lines 12 to 44 in 9089964