-
Notifications
You must be signed in to change notification settings - Fork 709
Description
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:
- Create a playbook with many tasks - this triggers
complexity[play]violations - Create a task file (e.g.,
tasks/main.yml) with many tasks - no complexity check is performed - Run
ansible-linton 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
Metadata
Metadata
Assignees
Labels
Type
Projects
Status