Quiz Entry - updated: 2026.11.26
The final output task pipes each result through json_query(...) | to_yaml | regex_replace('(?:- )+\[(.*)\]','\1'). What does each step do to the data?
json_query extracts [type, name, color] per object; to_yaml turns that nested list into text lines like - - [host, A-GUI, brown]; the regex removes the leading - markers and the brackets, leaving host, A-GUI, brown.
Step by step for one gateway:
json_query('ansible_facts.*.objects[*].[type,name,color]')→ a list of lists of lists:[[["simple-gateway", "A-GW", "black"]]](one level from*, one fromobjects[*], one from the multiselect).to_yaml→ the text- - [simple-gateway, A-GW, black]. YAML writes short lists inline in brackets and marks list nesting with-.regex_replace('(?:- )+\[(.*)\]', '\1'):(?:- )+matches one or more-at the start.(?:…)groups without capturing, and+means "repeat";\[and\]match the literal brackets (escaped, since[starts a character class);(.*)captures everything between them, and\1in the replacement puts back just that capture.
Result: simple-gateway, A-GW, black, one readable line per object. It is a pragmatic trick for a report; for data you process further, keep the structured list and use join or a template rather than editing YAML text with a regex.
Go deeper:
regex_replace filter (Ansible docs) — syntax and back-references.
to_yaml filter (Ansible docs) — how data is serialised to YAML text.
Regular expression (Wikipedia) — groups, quantifiers and escaping.