Skip to content

Commit

Permalink
fix(ansible): handle empty tasks (#6751)
Browse files Browse the repository at this point in the history
* Fix

* Fix graph
  • Loading branch information
tsmithv11 authored Oct 6, 2024
1 parent a3d96ee commit 9319c03
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 6 additions & 2 deletions checkov/ansible/graph_builder/local_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ def _create_vertices(self) -> None:

for code_block in definition:
if ResourceType.TASKS in code_block:
for task in code_block[ResourceType.TASKS]:
self._process_blocks(file_path=file_path, task=task)
tasks = code_block[ResourceType.TASKS]
if tasks: # Check if tasks is not None and not empty
for task in tasks:
self._process_blocks(file_path=file_path, task=task)
else:
self._process_blocks(file_path=file_path, task=code_block)
else:
self._process_blocks(file_path=file_path, task=code_block)

Expand Down
8 changes: 6 additions & 2 deletions checkov/ansible/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ def build_definitions_context(

for code_block in definition:
if ResourceType.TASKS in code_block:
for task in code_block[ResourceType.TASKS]:
_process_blocks(definition_raw=definition_raw, file_path_context=file_path_context, task=task)
tasks = code_block[ResourceType.TASKS]
if tasks: # Check if tasks is not empty
for task in tasks:
_process_blocks(definition_raw=definition_raw, file_path_context=file_path_context, task=task)
else:
_process_blocks(definition_raw=definition_raw, file_path_context=file_path_context, task=code_block)
else:
_process_blocks(definition_raw=definition_raw, file_path_context=file_path_context, task=code_block)

Expand Down
6 changes: 6 additions & 0 deletions tests/ansible/examples/empty_tasks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Using a Role
hosts: all
roles:
- role: somerolename
tasks:

0 comments on commit 9319c03

Please sign in to comment.