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

Inaccurate error for imported playbooks with invalid syntax #4257

Closed
kaeraali-flutterint opened this issue Jul 11, 2024 · 0 comments · Fixed by #4289
Closed

Inaccurate error for imported playbooks with invalid syntax #4257

kaeraali-flutterint opened this issue Jul 11, 2024 · 0 comments · Fixed by #4289
Labels

Comments

@kaeraali-flutterint
Copy link

Summary

When a playbook imports another playbook via import_playbook ansible-lint checks if that playbook exists. It does this by calling self.app.runtime.has_playbook

However, has_playbook actually does more than check whether the playbook exists. It also calls proc = self.run(["ansible-playbook", "--syntax-check", playbook], cwd=basedir). This means that has_playbook fails if there are syntax errors in the imported playbook

This in turn means that the ansible-lint error msg = f"Failed to find {v} playbook." is inaccurate. The playbook we are trying to import may very well exist but with invalid syntax

Issue Type
  • Bug Report
OS / ENVIRONMENT

This happens in both the latest code from GitHub and the version my team currently use

ansible-lint --version
ansible-lint 24.7.1.dev0 using ansible-core:2.17.1 ansible-compat:24.7.0 ruamel-yaml:0.18.6 ruamel-yaml-clib:0.2.8
You are using a pre-release version of ansible-lint.
ansible-lint --version
ansible-lint 24.5.0 using ansible-core:2.16.7 ansible-compat:24.6.0 ruamel-yaml:0.18.6 ruamel-yaml-clib:0.2.8
  • ansible installation method: pip
  • ansible-lint installation method: pip or source
STEPS TO REPRODUCE

Given a playbook that imports from a collection that we don't have:

web.yml:

---
- name: Web servers
  hosts: role_web_servers
  roles:
    - example.server.nginx

This fails ansible-playbook --syntax-check web.yml, which is expected

If we then try and use this playbook within linux.yml:

---
- import_playbook: web.yml

This fails on ansible-lint with ERROR Failed to find web.yml playbook. because of the failing syntax checks

Desired Behavior

ansible-lint should report something more useful than Failed to find web.yml playbook.

Perhaps it could tell us about the syntax error instead of claiming it couldn't find the imported playbook

Actual Behavior

It tells us Failed to find web.yml playbook. which makes us go searching for why it can't find the playbook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants