EX294 • Practice Test 37
Free EX294 practice test — 15 questions with explanations. Set 37. No signup required.
A senior automation engineer is optimizing a playbook that processes large amounts of data. The playbook uses the "json_query" filter to filter and extract specific fields from a complex JSON structure returned by an API. The engineer notices that the playbook runs very slowly and consumes a lot of memory. They suspect the json_query filter is inefficient for this use case. The engineer wants to replace json_query with a combination of built-in Ansible filters to improve performance. The JSON structure is as follows:
{
"servers": [
{"name": "web01", "status": "active", "role": "web"},
{"name": "web02", "status": "active", "role": "web"},
{"name": "db01", "status": "active", "role": "db"}
]
}The engineer needs to extract a list of server names where the status is "active" and the role is "web". The current code using json_query is: server_names: "{{ api_result | json_query(\"servers[?status=='active' && role=='web'].name\") }}" Which of the following alternatives uses only Ansible built-in filters (not json_query) and is likely to be more efficient?