Interview Prep/Ansible/Roles, Collections and Galaxy

How do you pass parameters to a role?

IntermediateConceptRoles, Collections and Galaxy
Answer

Either set variables the role reads from defaults/, or pass them inline. Inline parameters have a very high precedence (level 20), above set_fact and below only extra vars.

roles:
  - role: postgres
    vars:
      postgres_version: 16
      postgres_max_connections: 300

Use group_vars for environment values and inline parameters for role calls that differ within one playbook. Declare the interface with argument_specs so mistakes are caught early.

All Ansible questions Roadmap: Ansible

More on Roles, Collections and Galaxy