Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linter should consider the same paths that ansible.builtin.import_tasks uses to import relative paths #4474

Open
agross opened this issue Jan 14, 2025 · 1 comment
Labels
bug good first issue Bugs ideal for the first time, good for newcomers contributors

Comments

@agross
Copy link

agross commented Jan 14, 2025

Summary

The ansible.builtin.import_tasks module searches a list of directories to find the file that should be imported.

The linter should consider the same directories as candidate files instead of assuming the file is located in the role's tasks directory.

Issue Type
  • Bug Report
OS / ENVIRONMENT
$ ansible-lint --version
ansible-lint 24.12.2 using ansible-core:2.18.1 ansible-compat:24.10.0 ruamel-yaml:0.18.6 ruamel-yaml-clib:None
  • ansible installation method: Homebrew
  • ansible-lint installation method: Homebrew
STEPS TO REPRODUCE

Clone the reproduction: git clone https://github.com/agross/ansible-import-path.git

Tye linter is not happy:

$ ansible-lint
WARNING  Listing 2 violation(s) that are fatal
syntax-check[missing-file]: Unable to retrieve file contents
roles/importing:1:1 Could not find or access '/var/folders/c6/2ysv_j9j4hdgtzsnhrvflvtc0000gn/T/tasks/task-a.yml' on the Ansible Controller.

load-failure[filenotfounderror]: [Errno 2] No such file or directory: '/Users/agross/Downloads/ansible-import-path/task-a.yml'
task-a.yml:1


# Rule Violation Summary

  1 load-failure profile:min tags:core,unskippable
  1 syntax-check profile:min tags:core,unskippable

Failed: 2 failure(s), 0 warning(s) on 9 files.

The playbook works:

$ ansible-playbook playbook.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Demo] *********************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************
ok: [localhost]

TASK [importing : A name to make ansible-lint happy] ****************************************************************************************************
ok: [localhost] => {
    "msg": "local task was imported"
}

TASK [importing : A name to make ansible-lint happy] ****************************************************************************************************
ok: [localhost] => {
    "msg": "tasks/task-a.yml was imported"
}

TASK [importing : A name to make ansible-lint happy] ****************************************************************************************************
ok: [localhost] => {
    "msg": "tasks/task-a.yml was imported"
}

TASK [importing : A name to make ansible-lint happy] ****************************************************************************************************
ok: [localhost] => {
    "msg": "<root>/task-b.yml was imported"
}

PLAY RECAP **********************************************************************************************************************************************
localhost                  : ok=5    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
Desired Behavior

The linter should consider the same paths the module considers, i.e. search the tasks/ directory.

Actual Behavior

https://github.com/agross/ansible-import-path

$ ansible-playbook --syntax-check playbook.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

playbook: playbook.yml
@agross agross added bug new Triage required labels Jan 14, 2025
@shatakshiiii shatakshiiii removed the new Triage required label Jan 22, 2025
@agross
Copy link
Author

agross commented Feb 3, 2025

The same applies to the include_tasks module.

@ssbarnea ssbarnea added the good first issue Bugs ideal for the first time, good for newcomers contributors label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Bugs ideal for the first time, good for newcomers contributors
Projects
Status: No status
Development

No branches or pull requests

3 participants