ansible-lint icon indicating copy to clipboard operation
ansible-lint copied to clipboard

Extend complexity rule to check task files and handlers for excessive task counts

Open ARYPROGRAMMER opened this issue 6 months ago • 1 comments

Summary

Extend the complexity rule to check task files and handler files for excessive task counts, similar to how playbooks are currently checked. This would help maintain code quality by preventing overly complex task files that are hard to maintain and debug.

Issue Type
  • Feature Request
STEPS TO REPRODUCE

Currently, the complexity rule only checks playbooks for excessive task counts. For example:

  1. Create a playbook with many tasks - this triggers complexity[play] violations
  2. Create a task file (e.g., tasks/main.yml) with many tasks - no complexity check is performed
  3. Run ansible-lint on both - only the playbook shows complexity violations

Example task file that should trigger complexity check:

# tasks/main.yml
- name: Task 1
  debug:
    msg: "task 1"

- name: Task 2  
  debug:
    msg: "task 2"

# ... many more tasks (25+ tasks)
Desired Behavior

The complexity rule should also check task files and handler files for excessive task counts, triggering complexity[tasks] violations when the number of tasks exceeds the configured max_tasks limit (default: 20).

For the example above, running ansible-lint on a task file with 25 tasks should produce output like:

tasks/main.yml:1: complexity[tasks] File contains 25 tasks, exceeding the maximum of 20. Consider using `ansible.builtin.include_tasks` to split the tasks into smaller files.
Actual Behavior

Currently, task files and handler files are not checked for complexity. The complexity rule only applies to playbooks (complexity[play]) and block nesting (complexity[nesting]). Large task files with dozens or hundreds of tasks pass linting without any complexity warnings, potentially leading to maintainability issues.

# Current output for task file with many tasks:
$ ansible-lint tasks/main.yml
# No complexity violations reported

ARYPROGRAMMER avatar Oct 23 '25 05:10 ARYPROGRAMMER

solved in #4799

ARYPROGRAMMER avatar Oct 23 '25 05:10 ARYPROGRAMMER