Role Dependency Calculator
Map dependency depth and count across Ansible roles and their meta dependencies.
About Role Dependency Calculator
Ansible resolves role dependencies declared in each role's meta/main.yml before running the role itself, and by default loads each unique role only once per play even if multiple roles depend on it. This calculator expands direct roles across your dependency depth to estimate raw transitive dependency count, then applies a shared/duplicate fraction to approximate how many roles Ansible actually loads once deduplication is applied.
Formula
total_roles = direct_roles + raw_transitive × (1 - shared_fraction / 100)
- direct_roles
- Roles listed in the playbook
- raw_transitive
- Sum of deps expanded across all depth levels
- shared_fraction
- Percent of transitive deps that are deduplicated
Worked example
With the default values below, Role Dependency Calculator returns Total Unique Roles to Load of 31. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Direct Rolesaccepts 0–500 roles
- 6 roles
- Avg. Transitive Deps per Roleaccepts 0–50 deps/role
- 2 deps/role
- Dependency Chain Depthaccepts 1–20 levels
- 3 levels
- Shared Dependency Fractionaccepts 0–100 %
- 30 %
Results
- Total Unique Roles to Load
- 31 roles
- Transitive Dependencies (deduped)
- 25 roles
- Raw Transitive Dependencies
- 36 roles
- Dependency Chain Depth
- 3 levels
Step by step
- 1Raw transitive deps across depth= 36 deps
- 2After removing shared/duplicate deps= 25 deps
- 3Total unique roles: direct + deduped transitive= 31 roles
Assumptions and limits
- The result is derived only from the 4 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax or compounding frequency into account.
- Figures are rounded for display to whole numbers, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
Does Ansible run a shared dependency's tasks more than once?
No — by default, `allow_duplicates: false` in role meta means a role is only executed once per play even if several other roles list it as a dependency, which is why deduplication matters for an accurate total.
What determines load order?
Ansible performs a depth-first resolution: a role's dependencies run before the role itself, in the order declared. Circular dependencies will cause an error, so dependency graphs should be acyclic.
Why does dependency depth matter for maintainability?
Deep dependency chains (roles depending on roles depending on roles) make it hard to reason about execution order and increase the blast radius of a change to a low-level shared role — many teams cap depth at 2-3 levels.
How do I find my actual dependency count?
Use `ansible-galaxy role list` combined with inspecting each role's meta/main.yml, or run `ansible-playbook --list-tasks` which expands and prints the full resolved task list including role dependencies.
