Interview Prep/Ansible/Roles, Collections and Project Structure

Where do you put a variable users of your role are expected to override?

BeginnerScenarioRoles, Collections and Project Structure
Answer

Situation read → Public vs internal role variables.

What I'd do → defaults/main.yml for the public interface, vars/main.yml for internal constants.

# roles/nginx/defaults/main.yml
nginx_worker_processes: auto
nginx_listen_port: 80

Why → Defaults have the lowest precedence, so any inventory or play var wins; vars/ is high precedence and hard to override.

Interview tip → Prefix variables with the role name to avoid collisions.

All Ansible questions Roadmap: Ansible

More on Roles, Collections and Project Structure