Roles, Collections and Execution Environments
14. What belongs in a role, and when do you split one?
A role owns one component: install, configure and run it. The standard layout is tasks/, handlers/, defaults/, vars/, templates/, files/ and meta/, plus meta/argument_specs.yml, which validates role inputs before any task runs.
# roles/nginx/meta/argument_specs.yml
argument_specs:
main:
short_description: Install and configure nginx
options:
nginx_worker_processes:
type: str
default: auto
nginx_sites:
type: list
elements: dict
required: true
Split a role when two parts change for different reasons or are used without each other.
A strong candidate avoids roles that branch on a dozen when conditions to serve every OS and environment, and prefers include_tasks on ansible_facts['os_family'] with one file per family.
They also keep meta/main.yml dependencies rare, since a dependency runs implicitly and often runs more than once in a large play.
15. import_tasks or include_tasks: what is the difference?
import_* is static: Ansible reads the file when it parses the playbook, so the tasks appear in --list-tasks, tags on them work with --tags, and keywords on the import are copied to each task inside. include_* is dynamic: the file is loaded when the task runs, so the filename can come from a variable or a loop, but tags and when apply to the include itself.
The classic trap: when on an import_tasks is evaluated for every imported task, so if the first task changes the variable the condition reads, later tasks are skipped. On an include_tasks, the condition is evaluated once.
Candidates should also know that a handler written as an include_tasks can only be notified by the include's own name, not by the names of the tasks inside it, and that import_role and include_role follow the same split.
16. What is a collection, and how do you manage collection versions?
A collection is the distribution unit for modules, plugins, roles and playbooks under a namespace, such as community.postgresql.
Tasks should name modules by fully qualified collection name (ansible.builtin.copy, community.postgresql.postgresql_db) so that the right module runs regardless of what else is installed.
# collections/requirements.yml
collections:
- name: amazon.aws
version: ">=12.0.0,<13.0.0"
- name: community.postgresql
version: ">=5.0.0,<6.0.0"
- name: ansible.posix
Install with ansible-galaxy collection install -r collections/requirements.yml, ideally into the execution environment image rather than onto a laptop.
A strong answer pins ranges, says that an unpinned collection like ansible.posix above is a reproducibility gap, and mentions that ansible-galaxy dropped the v2 Galaxy server API in 2.20, so private collection servers must speak v3.
17. What is an execution environment, and why use one?
An execution environment (EE) is a container image that holds ansible-core, ansible-runner, collections, their Python packages and system libraries.
Runs use that image instead of whatever happens to be installed on the controller, so a playbook behaves the same on a laptop, in CI and in AWX or Automation Controller.
The ansible-builder docs describe how images are built from an execution-environment.yml file.
# execution-environment.yml
version: 3
images:
base_image:
name: quay.io/fedora/fedora:42
dependencies:
python_interpreter:
package_system: python3.13
python_path: /usr/bin/python3.13
ansible_core:
package_pip: ansible-core==2.22.0
ansible_runner:
package_pip: ansible-runner
galaxy: collections/requirements.yml
python: requirements.txt
system: bindep.txt
Build with ansible-builder build -t registry.example.com/ee/platform:2026.11. ansible-builder 3.2.0 deprecated schema versions 1 and 2, so a candidate still writing version: 1 files has not touched this recently.
The base image's Python must meet the 2.22 controller minimum of 3.13; confirm the version your base image ships before pinning it. Good candidates tag images by date or Git SHA and never run production from latest.
18. What does ansible-navigator add over ansible-playbook?
ansible-navigator runs playbooks inside an execution environment by default and provides a text UI for browsing plays, tasks and host results, plus subcommands to inspect what an EE contains (collections, doc, images, config).
Each run can write a JSON artifact that can be replayed later with ansible-navigator replay, which is useful for reviewing a failed CI run.
ansible-navigator run site.yml \
-i inventories/prod \
--eei registry.example.com/ee/platform:2026.11 \
--mode stdout \
--pull-policy missing
Settings live in ansible-navigator.yml in the project, so the whole team runs the same image. The current release is ansible-navigator 26.11.0 (November 5, 2026); 26.10.0 added limited Apple Container support as a container engine.
A candidate should know the trade-off: SSH agent forwarding, file paths and inventory plugins that call cloud APIs all have to work from inside the container, which is where most first-day problems come from.
19. How do you test roles and collections?
Layer the checks from cheap to expensive:
- ansible-lint (26.11.0 as of November 5, 2026) for syntax, FQCN use, risky shell tasks, missing
name, and the production profile in CI.
ansible-playbook --syntax-check and --check --diff against a staging inventory.
- Molecule to create a disposable instance, apply the role, run it a second time to prove idempotence, and run verify tasks.
ansible-test sanity and ansible-test units for collections that ship Python modules or plugins.
The weak answer stops at lint. The strong answer runs Molecule's idempotence step in CI for every role, uses the same EE image in CI as in production, and has at least one integration test that hits a real API for modules that wrap one.
Our CI/CD interview guide covers the pipeline side.