Skip to content

Commit

Permalink
evaluate tags on include_role
Browse files Browse the repository at this point in the history
  • Loading branch information
haidaraM committed Mar 23, 2024
1 parent 4523148 commit 6cbca25
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
6 changes: 6 additions & 0 deletions ansibleplaybookgrapher/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ def _include_tasks_in_blocks(
# See :func:`~ansible.playbook.included_file.IncludedFile.process_include_results` from line 155
display.v(f"An 'include_role' found: '{task_or_block.get_name()}'")

if not task_or_block.evaluate_tags(
only_tags=self.tags, skip_tags=self.skip_tags, all_vars=task_vars
):
display.vv(f"The include_role '{task_or_block.get_name()}' is skipped due to the tags.")
continue # Go to the next task

# Here we are using the role name instead of the task name to keep the same behavior as a
# traditional role
if self.group_roles_by_name:
Expand Down
2 changes: 0 additions & 2 deletions tests/fixtures/play-hiding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
- name: Include role
include_role:
name: fake_role
apply:
tags: include-role


- hosts: host3 # This should not be displayed when --hide-empty-plays is set
Expand Down
34 changes: 29 additions & 5 deletions tests/test_graphviz_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def test_hiding_plays(request):
svg_path=svg_path,
playbook_paths=playbook_paths,
plays_number=2,
roles_number=1,
roles_number=2,
tasks_number=1,
)

Expand Down Expand Up @@ -610,6 +610,30 @@ def test_hiding_plays_without_roles(request):
"""
Test hiding plays with the flag --hide-plays-without-roles
:param request:
:return:
"""
svg_path, playbook_paths = run_grapher(
["play-hiding.yml"],
output_filename=request.node.name,
additional_args=[
"--hide-plays-without-roles",
],
)

_common_tests(
svg_path=svg_path,
playbook_paths=playbook_paths,
plays_number=2,
roles_number=2,
tasks_number=1,
)


def test_hiding_plays_without_roles_with_tags_filtering(request):
"""
Test hiding plays with the flag --hide-plays-without-roles
Also apply some tags filter
:param request:
:return:
Expand All @@ -620,15 +644,15 @@ def test_hiding_plays_without_roles(request):
additional_args=[
"--hide-plays-without-roles",
"--tags",
"play1,include-role",
"play1",
"--include-role-tasks",
],
)

_common_tests(
svg_path=svg_path,
playbook_paths=playbook_paths,
plays_number=2,
roles_number=2,
tasks_number=8,
plays_number=1,
roles_number=1,
tasks_number=5,
)

0 comments on commit 6cbca25

Please sign in to comment.