Be able to chain Jinja2 filters such as selectattr, map, and list to extract values from lists of dictionaries, and use lookup plugins correctly. The most important thing is verifying filter order and data type, since a wrong sequence silently returns the wrong structure.
Start practicing
Transform data with filters and plugins — choose a session length
Free · No account required
Domain overview
This domain covers Ansible data transformation using Jinja2 filters, lookups, and plugin collections. You must select, map, and reshape structured data from variables, JSON API responses, and fact dictionaries inside playbooks. Questions test filter syntax, lookup plugin usage, and correct handling of lists of dictionaries within tasks and templates.
Exam objectives
Applying Jinja2 filters like selectattr, map, and json_query to lists of dictionaries
Using lookup plugins such as community.general.dig to resolve host addresses dynamically
Transforming API JSON responses into filtered lists for downstream task consumption
Referencing nested dictionary keys and list elements correctly in Ansible templates
Confusing selectattr with map, or chaining them in the wrong order, which returns dictionaries instead of the intended scalar values.
Forgetting that lookup plugins run on the control node, not the managed host, so host-specific facts are unavailable.
Treating a JSON string as already-parsed data; you must use from_json before applying filters or indexing keys.
Click any question to see the full explanation and answer options, or start a focused practice session above.
A playbook needs to set a fact 'total_memory' by summing the 'memory_mb' values from a list of servers. Which filter should be used?
2The playbook uses the community.general.parse_csv filter. Assuming the collection is installed, what is the type and structure of the 'parsed' variable?
3A playbook uses the 'debug' module to print a variable 'my_var' but the output is 'VARIABLE IS UNDEFINED'. The variable is defined in group_vars/all.yml. Which filter could be used to provide a default value and avoid this error?
4Drag and drop the steps to set up a cron job that runs a script every day at 2 AM in the correct order.
5A playbook uses `{{ my_var | default('fallback') }}`. What is the effect?
6You have a list `my_list` containing `[0, 1, 2, '', 'hello']`. You want to extract the first truthy element that exists. Which chain achieves this?
7Consider the task: `- debug: msg={{ item | upper }}` with `loop: "{{ ['a','b'] }}"`. What will be the output?
8Given `{{ ['1', '2', '3'] | map('int') | list }}`, what is the result?
9Which TWO filters are commonly used for list manipulation in Ansible? (Select exactly two.)
10Which THREE of the following are valid Ansible lookup plugins? (Select exactly three.)
11What is the effect of the `filter_plugins` setting in `ansible.cfg`?
12What is the output of the following playbook task? ```yaml - name: Example task debug: msg: "{{ ['apple', 'banana'] | map('upper') | first }}" ```
13An Ansible playbook needs to convert a list of server names into a comma-separated string for an API call. Which filter should be applied to the list variable 'server_list'?
14An administrator must parse an inventory file where hostnames are stored in YAML format under a list 'nodes'. The task needs to extract only hostnames that contain 'prod' in the name, then sort them in reverse order. Which combination of filters in a single Ansible expression achieves this?
15A playbook needs to generate a default value for a variable if it is undefined or empty. Which filter with a default value should be used?
16A security team requires that all passwords in an Ansible vault be encrypted with a different key from the host variables. They want to use a custom lookup plugin that fetches secrets from an external API. Which plugin type should be developed?
17An Ansible playbook needs to dynamically include a set of variables based on the environment (dev/staging/prod). The developer wants to use a variable from a lookup plugin that returns a YAML file path. Which lookup plugin is most appropriate for fetching a file’s contents?
18A company uses Ansible Tower and has defined a custom inventory script. The inventory returns JSON with nested groups. The playbook needs to list all hosts from a specific group 'webservers' that are not in the 'drain' subgroup. Which combination of filters correctly extracts these hosts?
19Which TWO filters are commonly used to transform strings in Ansible? (Select exactly two.)
20Which THREE features are provided by Ansible's filter plugins? (Select exactly three.)
21Refer to the exhibit. What is the output of the debug task?
22An Ansible playbook retrieves a JSON response from an API and stores it in the variable `api_response`. The JSON structure is a list of objects, each with keys `name`, `status`, and `id`. The team needs to create a list of names for objects where status is 'active'. Which filter should be used?
23An administrator needs to combine two dictionaries, `base_config` and `user_config`, where keys in `user_config` should override keys in `base_config`, and nested dictionaries should be merged recursively. Which filter syntax achieves this?
24A developer wrote a custom filter plugin in a Python file `my_filters.py` and placed it in the directory `./filter_plugins/`. The playbook fails with 'ERROR! no filter named 'my_custom_filter''. The playbook is located in `/home/user/project/playbook.yml`. The `ansible.cfg` file in the same directory does not set `filter_plugins`. Which is the most likely cause?
25An Ansible task uses the variable `{{ my_var | default(required=true) }}`. What happens if `my_var` is undefined?
26Given a list of dictionaries `users` with keys `name` and `role`, a playbook needs to create a list of names where role is 'admin'. Which expression achieves this?
27A playbook has a dictionary `config` that maps service names to ports. The team wants to iterate over both keys and values in a task. Which filter should be used to convert the dictionary into a list of key-value pairs?
28Which TWO filters are commonly used to manipulate JSON data in Ansible? (Select exactly two.)
29Which TWO filters can be used to conditionally select elements from a list based on a test? (Select exactly two.)
30An Ansible role uses a variable "server_list" which is a list of dictionaries. Each dictionary has a key "ports" which should be a list of integers. However, due to inconsistent input, "ports" could be a comma-separated string (e.g., "80,443") or already a list of integers (e.g., [80,443]). The engineer wants to normalize "ports" to always be a list of integers for further processing. Which of the following tasks correctly normalizes the "ports" field?
31An Ansible playbook uses the "community.general" collection to manage firewall rules. The engineer wants to use a lookup plugin to fetch the current IPv4 address of a host to include in a dynamic inventory script. Which TWO of the following options correctly describe the usage of lookup plugins in Ansible?
32An administrator is writing a playbook to manage multiple web servers. The playbook uses a variable "server_facts" which is a list of dictionaries with keys "hostname", "ip", and "status". The administrator needs to extract a list of all hostnames where status is "online". The administrator writes: - name: Get online hosts set_fact: online_hosts: "{{ server_facts | selectattr('status', '==', 'online') | map(attribute='hostname') | list }}" However, when running the playbook, the "selectattr" filter fails with an error: "Invalid data passed to filter". The administrator checks the structure of "server_facts" and confirms it is a list of dicts with the expected keys. What is the most likely cause of the error?
33An Ansible playbook is used to generate configuration files for network devices. The variables are defined in a vars file like: --- interfaces: - name: GigabitEthernet1 ip: 192.168.1.1/24 - name: GigabitEthernet2 ip: 10.0.0.1/24 The playbook uses a Jinja2 template to render the config. The template iterates over interfaces and writes "ip address" lines. However, the designer wants to support an additional field "secondary_ips" which is a list of IP addresses (e.g., ["192.168.2.1/24", "192.168.3.1/24"]). In the template, they want to generate multiple "ip address" lines for each interface, one for the primary IP and one for each secondary IP. The following template fragment is used: {% for iface in interfaces %} interface {{ iface.name }} ip address {{ iface.ip }} {% for sec in iface.secondary_ips|default([]) %} ip address {{ sec }} {% endfor %} {% endfor %} This works when secondary_ips is defined. However, some interfaces have secondary_ips defined as a string (e.g., "192.168.2.1/24") instead of a list. The playbook fails because the inner loop tries to iterate over a string. The engineer wants to normalize the data in the playbook before passing to the template, so that secondary_ips is always a list. Which of the following set_fact tasks will correctly transform the interfaces list to ensure secondary_ips is always a list (even if missing or a string)?
34An Ansible automation is used to manage firewall rules on a set of Linux servers. The playbook defines a variable "allow_rules" as: allow_rules: - proto: tcp dport: 80 comment: HTTP - proto: tcp dport: 443 comment: HTTPS The engineer needs to use the "iptables" module to create rules. The module expects "chain" to be specified, and the engineer wants to dynamically set the chain based on the port: ports 80 and 443 go to "INPUT" chain, while others go to "FORWARD". The engineer writes a loop: - name: Add iptables rules iptables: chain: "{{ item.dport | map('some_filter') }}" protocol: "{{ item.proto }}" destination_port: "{{ item.dport }}" comment: "{{ item.comment }}" loop: "{{ allow_rules }}" But this fails because the chain field expects a string, not a list. The engineer realizes the map filter returns a list. Which of the following modifications correctly sets the chain based on port number?
35A playbook reads a JSON inventory file with `lookup('file', 'hosts.json') | from_json` and registers it as `hostdata`. The structure is a top-level dictionary where each key is a hostname and each value is a dictionary of attributes, for example `{"web1": {"env": "prod", "cpu": 4}, "db1": {"env": "dev", "cpu": 8}}`. You must build a list containing only the hostnames whose `env` attribute equals `prod`. Which task correctly produces that list?
36A playbook reads a YAML file containing a list of dictionaries named `packages`, where each dictionary has keys `name`, `version`, and `enabled`. You need to produce a comma-separated string of only the `name` values for all entries where `enabled` is true. Which Jinja2 expression accomplishes this in a single task variable assignment?
37A playbook reads a YAML configuration file with the `include_vars` module and registers the result. The variable `app_config` now holds a dictionary with keys `database`, `cache`, and `logging`. You need to produce a list containing only the top-level key names for a later loop. Which Jinja2 filter expression should you use in the task that builds this list?
38A task registers the output of a command that returns a string containing a JSON document in `result.stdout`. You must extract the numeric value at `metrics.cpu.load` and use it as an integer in a subsequent comparison. Which expression correctly parses the string and retrieves the integer value?
39A playbook reads a JSON file on the control node with the `file` lookup and registers the content as a string named `raw_config`. A task must convert that string into a native Python dictionary so later tasks can reference keys such as `raw_config.database.port`. Which filter should be applied to the registered content?
40A playbook registers the output of a command that returns a JSON string inside stdout. The string contains a top-level key 'services' with a nested list of dictionaries. You need to convert that string into native data so you can select only entries where the 'state' key equals 'running'. Which expression accomplishes this?
41A playbook defines the variable `packages` as a list of dictionaries, each containing `name` and `version` keys. You need to build a new list of strings in the form `name-version` for use in a log message. Which filter combination produces this result?
42A playbook registers the output of the `package_facts` module and must build a list containing only the version strings of installed packages whose name begins with 'httpd'. Which filter pipeline extracts those versions?
43A template must emit a comma-separated string of hostnames from a list variable `web_nodes`, sorted alphabetically, for use in a configuration file. Which expression produces that string?
44You maintain a variable inventory_hostnames that is a list of FQDN strings such as 'web01.example.com'. A template must produce a new list containing only the hostname portion before the first dot for each entry, preserving order. Which Jinja2 expression using Ansible filters achieves this?
45A playbook must normalize a list of dictionaries read from a YAML file. Each dictionary has keys 'name' and 'ports', where 'ports' is a comma-separated string such as '80,443'. You need to produce a new list where each dictionary has the same 'name' but 'ports' is a list of integers. Which TWO filter usages are required to accomplish this transformation? (Choose two.)
46A template must display the value of a variable named app_port. If app_port is undefined, the template should render the number 8080 instead of failing. Which expression accomplishes this using an Ansible filter?
47A playbook must merge a base dictionary of defaults with an override dictionary, where the override may contain nested dictionaries that should be merged recursively rather than replaced. Which filter expression performs a recursive merge?
48A task sets a variable `raw_size` to the string `'2048'`. You need to pass this value to a module parameter that expects an integer. Which filter should be applied to `raw_size` to achieve the correct type?
49A playbook registers the output of a shell command that returns a JSON string. You need to parse this JSON string into a usable dictionary within the same play. Which filter should you apply to the registered variable?
50You are writing a playbook that needs to transform a list of strings representing file paths. You want to extract only the base filenames (without directory paths) and ensure they are all lowercase. Which TWO filters should you use in your Jinja2 expression? (Choose two.)
Deep-dive questions
The most-searched questions in this domain — detailed explanations, worked examples, full answer breakdowns.
Be able to chain Jinja2 filters such as selectattr, map, and list to extract values from lists of dictionaries, and use lookup plugins correctly. The most important thing is verifying filter order and data type, since a wrong sequence silently returns the wrong structure.
The Courseiva EX294 question bank contains 50 questions in the Transform data with filters and plugins domain, covering the 12% of the exam attributed to this domain in the official Red Hat blueprint. Click any question to see the full explanation and answer breakdown.
Start with a 10-question focused session to identify your baseline accuracy in this domain. Read every explanation — even for questions you answer correctly — to understand the reasoning. Once you score consistently above 80%, move to a 20–30 question session to confirm depth before moving to the next domain.
Yes — the session launcher on this page draws questions exclusively from the Transform data with filters and plugins domain. Choose 10, 20, 30, or 50 questions for a focused session, or click individual questions to review them one by one.
Save your results, see per-domain analytics, and get readiness scores — free, for every certification.
Sign Up FreeFree forever · Every certification included