EX294 · domain
Transform data with filters and plugins
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.
Focused practice
Practice Transform data with filters and plugins questions
Scored sessions drawing only from this domain — pick a length below.
Start 20-question practice test →What this domain covers
What to know about Transform data with filters and plugins
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.
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
Watch out for
Common Transform data with filters and plugins exam traps
- ▸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.
Question index
All Transform data with filters and plugins questions (50)
Click any question to see the full explanation, or start a practice session above.
Consider the task: `- debug: msg={{ item | upper }}` with `loop: "{{ ['a','b'] }}"`. What will be the output?
Medium2An 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?
Medium3A 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.)
Medium4A 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?
Easy5You have a list `my_list` containing `[0, 1, 2, '', 'hello']`. You want to extract the first truthy element that exists. Which chain achieves this?
Medium6A 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?
Medium7An 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?
Hard8A 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?
Easy9An Ansible task uses the variable `{{ my_var | default(required=true) }}`. What happens if `my_var` is undefined?
Easy10An 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'?
Medium11Which THREE features are provided by Ansible's filter plugins? (Select exactly three.)
Medium12Which TWO filters are commonly used to transform strings in Ansible? (Select exactly two.)
Easy13What is the effect of the `filter_plugins` setting in `ansible.cfg`?
Hard14Given 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?
Medium15What is the output of the following playbook task? ```yaml - name: Example task debug: msg: "{{ ['apple', 'banana'] | map('upper') | first }}" ```
Easy16An 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?
Medium17You 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?
Hard18A 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?
Easy19A 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?
Easy20Which TWO filters are commonly used to manipulate JSON data in Ansible? (Select exactly two.)
Medium21A 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?
Medium22An 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?
Hard23An 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?
Hard24A 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?
Medium25Refer to the exhibit. What is the output of the debug task?
Easy26Which TWO filters are commonly used for list manipulation in Ansible? (Select exactly two.)
Easy27A 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?
Hard28Which TWO filters can be used to conditionally select elements from a list based on a test? (Select exactly two.)
Easy29A 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?
Medium30A 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?
Hard31Which THREE of the following are valid Ansible lookup plugins? (Select exactly three.)
Hard32A 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?
Hard33An 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)?
Medium34A 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?
Hard35A 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?
Medium36A 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?
Medium37A playbook needs to set a fact 'total_memory' by summing the 'memory_mb' values from a list of servers. Which filter should be used?
Easy38Given `{{ ['1', '2', '3'] | map('int') | list }}`, what is the result?
Hard39The playbook uses the community.general.parse_csv filter. Assuming the collection is installed, what is the type and structure of the 'parsed' variable?
Medium40A 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?
Medium41A 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?
Medium42You 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.)
Medium43A 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?
Easy44A 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?
Hard45Drag and drop the steps to set up a cron job that runs a script every day at 2 AM in the correct order.
Medium46A 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?
Medium47An 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?
Easy48An 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?
Medium49An 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?
Easy50A playbook uses `{{ my_var | default('fallback') }}`. What is the effect?
EasyOther domains
All EX294 exam domains
Frequently asked questions
- What does the Transform data with filters and plugins domain cover on the EX294 exam?
- 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.
- How many questions are in this domain?
- This page lists all 50 Transform data with filters and plugins questions in the EX294 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
- What is the best way to practise this domain?
- Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
- Can I practise only Transform data with filters and plugins questions?
- Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.