Skip to content

Commit

Permalink
Recognize import_tasks with file key (#2019)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Mar 18, 2022
1 parent c4e8857 commit dbd10e7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions examples/playbooks/common-include-1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
tasks:
- name: some include
ansible.builtin.include: tasks/included-with-lint.yml
- name: some include_tasks with file and jinja2
ansible.builtin.include_tasks:
file: "{{ 'tasks/included-with-lint.yml' }}"
3 changes: 3 additions & 0 deletions examples/playbooks/playbook-parent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

- name: Importing playbook from collection
import_playbook: community.molecule.validate

- name: Importing playbook using jinja2
import_playbook: "{{ 'community.molecule.validate' }}"
16 changes: 11 additions & 5 deletions src/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import re
import warnings
from argparse import Namespace
from collections.abc import ItemsView
from collections.abc import ItemsView, Mapping
from functools import lru_cache
from pathlib import Path
from typing import (
Expand Down Expand Up @@ -290,6 +290,10 @@ def _include_children(
):
v = v["file"]

# we cannot really parse any jinja2 in includes, so we ignore them
if "{{" in v:
return []

if "import_playbook" in k and COLLECTION_PLAY_RE.match(v):
# Any import_playbooks from collections should be ignored as ansible
# own syntax check will handle them.
Expand Down Expand Up @@ -392,10 +396,12 @@ def _get_task_handler_children_for_tasks_or_playbooks(
if not task_handler:
continue

# import pdb; pdb.set_trace()
return Lintable(
path_dwim(basedir, task_handler[task_handler_key]), kind=child_type
)
file_name = task_handler[task_handler_key]
if isinstance(file_name, Mapping) and file_name.get("file", None):
file_name = file_name["file"]

f = path_dwim(basedir, file_name)
return Lintable(f, kind=child_type)

raise LookupError(
f'The node contains none of: {", ".join(task_include_keys)}',
Expand Down

0 comments on commit dbd10e7

Please sign in to comment.