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

False positive load-failure when using import_tasks / include_tasks inside a block

Open to-bar opened this issue 2 years ago • 4 comments

Summary

PR #2202 for #1446 fixed many false load-failure violations we have. However, it seems the fix doesn't handle cases when include_tasks is placed inside a block.

Issue Type
  • Bug Report
Ansible and Ansible Lint details
ansible --version
ansible [core 2.12.6]
  config file = None
  configured module search path = ['/home/vscode/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/vscode/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.10.5 (main, Jun  7 2022, 18:49:47) [GCC 10.2.1 20210110]
  jinja version = 3.1.2
  libyaml = False

ansible-lint --version
ansible-lint 6.3.0 using ansible 2.12.6
  • ansible installation method: pip
  • ansible-lint installation method: pip
OS / ENVIRONMENT

Debian GNU/Linux 11

STEPS TO REPRODUCE
  1. Create the following layout:
issue
├── playbook.yml
└── role
    └── tasks
        ├── helpers
        │   └── foo.yml
        └── subdir
            └── test.yml

role/tasks/subdir/test.yml:

- name: block1
  block:
    - include_tasks: helpers/foo.yml

- name: block2
  block:
    - import_tasks: helpers/foo.yml

- include_tasks: helpers/foo.yml

role/tasks/helpers/foo.yml:

- name: Print foo
  debug:
    msg: foo

playbook.yml:

- hosts: localhost
  connection: local
  tasks:
    - include_role:  # noqa unnamed-task
        name: role
        tasks_from: subdir/test
  1. Run command:
$ ansible-lint issue/role/tasks/subdir/test.yml
WARNING  Listing 1 violation(s) that are fatal
issue/role/tasks/subdir/helpers/foo.yml:1: load-failure (load-failure[filenotfounderror])

There is no any violation when test.yml contains only:

- include_tasks: helpers/foo.yml
Desired Behavior

No load-failure violation.

Actual Behavior
WARNING  Listing 1 violation(s) that are fatal
issue/role/tasks/subdir/helpers/foo.yml:1: load-failure (load-failure[filenotfounderror])

to-bar avatar Jun 15 '22 13:06 to-bar

A PR would be welcomed here.

ssbarnea avatar Jul 06 '22 13:07 ssbarnea

I can take a look if no one else is working on this

lbenezriravin avatar Jul 27 '22 18:07 lbenezriravin

You are more than welcomed to do so!

ssbarnea avatar Jul 27 '22 20:07 ssbarnea

I see this issue occurring with both import_tasks and include_tasks if one task is including another task in the same folder. For example...

Directory structure:

issue
├── playbook.yml
└── role
    └── tasks
        └── helpers
            └── foo.yml
            └── test.yml

foo.yml

- block:
  - import_tasks: helpers/test.yml

Shows the error

- block:
  - import_tasks: test.yml

Does not show the error

Both seem to be acceptable to Ansible, but the latter will not work with some of our playbooks because it can't find the task.

derek126 avatar Aug 05 '22 19:08 derek126