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

Misleading warning "is not valid under any of the given schemas" when linting tasks again #3695

Closed
alqu opened this issue Aug 30, 2023 · 2 comments · Fixed by #3701
Closed
Assignees
Labels

Comments

@alqu
Copy link

alqu commented Aug 30, 2023

Summary

I have a task file that is part of a role which is used by a top-level playbook.
Ansible-lint reports a warning when checking the following file whereas I believe it is mistaken because the task works as expected. I suspect the environment key to cause the warning.

This has been already reported on #2888, but is popping up again somehow.

Issue Type
  • Bug Report
OS / ENVIRONMENT
ansible-lint --version
# outputs: ansible-lint 6.18.0 using ansible-core:2.15.3 ansible-compat:4.1.7 ruamel-yaml:0.17.32 ruamel-yaml-clib:0.2.7
  • ansible installation method: pip
  • ansible-lint installation method: pip
  • OS: MacOS 13.5.1
  • Python: 3.11.5
STEPS TO REPRODUCE

Create the following test.yml file inside a tasks folder of a local role, e.g. roles/myrole/tasks/main.yml:

---
- name: Run npm run prod
  ansible.builtin.command: npm run prod
  environment:
    DISABLE_V8_COMPILE_CACHE: 1
  changed_when: false

Run ansible-lint:

ansible-lint roles/myrole/tasks/main.yml
Desired Behavior

No warning is issued.

Actual Behavior

A warning is issued.

WARNING  Listing 1 violation(s) that are fatal
schema[tasks]: {'name': 'Check some command', 'ansible.builtin.command': {'cmd': 'someCommand'}, 'environment': {'my_env_var': 1}, 'register': 'command_result', 'failed_when': 'command_result.rc > 2', 'changed_when': "command_result.stdout != ''"} is not valid under any of the given schemas
@alqu alqu added bug new Triage required labels Aug 30, 2023
@shatakshiiii shatakshiiii removed the new Triage required label Aug 30, 2023
@ssbarnea
Copy link
Member

The warning is valid but the error that comes from the python JSON schema validator is of poor quality, not being specific enough.

You can fix the issue very easy by adding quotes around "1".

The funny part is that using the same schema, YAML-language-server is able to give a very good error message, only the python-json-schema validator gives the poor one, and that is the one used by ansible-lint.

We need to keep this bug open till we find a way to improve the error messages, at least for something as simple as this one.

@alqu
Copy link
Author

alqu commented Aug 30, 2023

Thanks! This little trick works like a charm.

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

Successfully merging a pull request may close this issue.

3 participants