Playbook Complexity Calculator
Score an Ansible playbook's complexity from task count, roles and conditional logic.
About Playbook Complexity Calculator
This weighted score approximates cognitive and maintenance load: score = tasks×1 + roles×3 + conditionals×2 + loops×2 + handlers×1. Roles are weighted heaviest because each one pulls in its own tasks, defaults, vars and dependency graph; conditionals and loops are weighted above plain tasks because they multiply the number of execution paths a reader must trace mentally.
Formula
complexity = tasks × 1 + roles × 3 + conditionals × 2 + handlers × 1.5
- tasks
- Total task count
- roles
- Number of roles included
- conditionals
- Tasks with when/loop/block conditions
- handlers
- Number of handlers defined
Worked example
With the default values below, Playbook Complexity Calculator returns Playbook Complexity Score of 106. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Tasksaccepts 0–10,000 tasks
- 45 tasks
- Rolesaccepts 0–1,000 roles
- 5 roles
- Conditionals (when:)accepts 0–10,000 conditionals
- 12 conditionals
- Loops (loop:/with_*)accepts 0–10,000 loops
- 8 loops
- Handlersaccepts 0–10,000 handlers
- 6 handlers
Results
- Playbook Complexity Score
- 106
- Rating
- Moderate — manageable with good structure
- Roles Contribution
- 15
- Conditionals Contribution
- 24
- Loops Contribution
- 16
Step by step
- 1Tasks: tasks × 1= 45
- 2Roles: roles × 3= 15
- 3Conditionals: conditionals × 2= 24
- 4Loops: loops × 2= 16
- 5Handlers: handlers × 1= 6
- 6Total complexity score= 106 (Moderate — manageable with good structure)
Assumptions and limits
- The result is derived only from the 5 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges 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
Why do roles score higher per unit than tasks?
A role isn't just one unit of work — it's an entire bundle of tasks, defaults, handlers and dependencies, so each role included in a playbook adds substantially more surface area to understand and maintain than a single task, which the ×3 weight reflects.
What should I do if my score is 'very complex'?
Look for opportunities to extract repeated task blocks into roles (paradoxically reducing playbook-level complexity even though it doesn't reduce total logic), replace deeply nested `when:` conditions with clearer role/host-group targeting, and add molecule tests to compensate for the harder-to-reason-about logic.
Does this score correlate with actual bugs?
Not directly measured here, but the components it tracks (conditionals, loops, deep role graphs) are well-established complexity drivers in software generally, and Ansible playbooks are no exception — more branching logic means more paths to test and more ways for edge cases to slip through.
Should I aim for a specific score?
There's no universal target — track the score over time per playbook and treat a sudden jump as a signal to review, rather than chasing an absolute number.
