Skip to content
Calcrivo

Playbook Complexity Calculator

Score an Ansible playbook's complexity from task count, roles, conditionals, loops and handlers.

Inputs

tasks

Total individual tasks (weight ×1).

roles

Roles included or imported (weight ×3).

conditionals

Tasks/blocks using `when:` (weight ×2).

loops

Tasks using loop constructs (weight ×2).

handlers

Notify-triggered handlers (weight ×1).

Playbook Complexity Score

106

Rating

Moderate — manageable with good structure

Roles Contribution

15

Conditionals Contribution

24

Loops Contribution

16

Step by step

  1. Tasks: tasks × 1

    45 × 1

    = 45

  2. Roles: roles × 3

    5 × 3

    = 15

  3. Conditionals: conditionals × 2

    12 × 2

    = 24

  4. Loops: loops × 2

    8 × 2

    = 16

  5. Handlers: handlers × 1

    6 × 1

    = 6

  6. Total complexity score

    45 + 15 + 24 + 16 + 6

    = 106 (Moderate — manageable with good structure)

How it works

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

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.

You might also need