LOGBOOK

HELP

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:

  1. json_query('ansible_facts.*.objects[*].[type,name,color]') → a list of lists of lists: [[["simple-gateway", "A-GW", "black"]]] (one level from *, one from objects[*], one from the multiselect).
  2. to_yaml → the text - - [simple-gateway, A-GW, black]. YAML writes short lists inline in brackets and marks list nesting with - .
  3. 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 \1 in 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:

From Quiz: ITIA / Network Automation with Ansible and a Check Point Firewall | Updated: Nov 26, 2026