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

Version 5.0.0 lints variable files as if they were playbooks #1357

Closed
emulanob opened this issue Feb 15, 2021 · 6 comments · Fixed by #1360
Closed

Version 5.0.0 lints variable files as if they were playbooks #1357

emulanob opened this issue Feb 15, 2021 · 6 comments · Fixed by #1360
Labels

Comments

@emulanob
Copy link

Summary
Issue Type
  • Bug Report
Ansible and Ansible Lint details
ansible --version
ansible 2.9.14
  config file = None
  configured module search path = ['~/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.5 (default, Jul 21 2020, 10:48:26) [Clang 11.0.3 (clang-1103.0.32.62)]

ansible-lint --version
ansible-lint 5.0.0
  • ansible installation method: pip
  • ansible-lint installation method: pip
OS / ENVIRONMENT

Reproducible on macOS 11.2.1 and python:3-slim docker image

STEPS TO REPRODUCE

Try linting a variable file, such as your role/defaults/main.yaml or any file you use in a vars_files argument.

Desired Behaviour

Like in version 4.2.0 (last one installed before the upgrade), ansible-lint should return no issues and return_code 0.

Actual Behaviour

In version 5.0.0, ansible-lint will return

syntax-check: A playbook must be a list of plays, got a <class 'ansible.parsing.yaml.objects.AnsibleMapping'> instead
ERROR! A playbook must be a list of plays, got a <class 'ansible.parsing.yaml.objects.AnsibleMapping'> instead
@emulanob emulanob added the bug label Feb 15, 2021
@ssbarnea
Copy link
Member

ssbarnea commented Feb 15, 2021

You failed to mention the most important bits: command line used to executed the linter and the file content. The full path of the file is essential in deciding the file type.

My guess is that your file path is not really fitting into the patterns from: https://github.com/ansible-community/ansible-lint/blob/master/src/ansiblelint/config.py#L15-L29

@emulanob
Copy link
Author

Consider the file vars/common/vault-common.yml:

vault_version: 1.6.1
$ ansible-lint vars/common/vault-common.yml
Added ANSIBLE_ROLES_PATH=roles
WARNING  Overriding detected file kind 'yaml' with 'playbook' for given positional argument: vars/common/vault-common.yml
WARNING  Listing 1 violation(s) that are fatal
syntax-check: A playbook must be a list of plays, got a <class 'ansible.parsing.yaml.objects.AnsibleMapping'> instead
vars/common/vault-common.yml:1:1 [WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'
ERROR! A playbook must be a list of plays, got a <class 'ansible.parsing.yaml.objects.AnsibleMapping'> instead

The error appears to be in '/Users/kdubonalume/projects/jini_ansible_playbooks/vars/common/vault-common.yml': line 1, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


vault_version: 1.6.1
^ here


You can skip specific rules or tags by adding them to your configuration file:
# .ansible-lint
warn_list:  # or 'skip_list' to silence them completely
  - syntax-check  # Ansible syntax check failed
Finished with 1 failure(s), 0 warning(s) on 1 files.

@emulanob
Copy link
Author

I'm guessing {"vars": "**/{vars,defaults}/*.{yaml,yml}"}, doesn't support another sublevel(s) between vars and the file itself, right?

@ssbarnea
Copy link
Member

That may be true and fixable, we need to update both the pattern and the test file to be sure that your case is recognised, especially as I find it as making sense.

@emulanob
Copy link
Author

emulanob commented Feb 15, 2021

No worries, I'll stay on 4.2.0 for now.
And if I may present my supporting evidence, this is our repo structure:

vars/
-- common/
-- production1/
-- production2/
-- testing/

@yan12125
Copy link
Contributor

This issue appears to affect files under host_vars and group_vars, too.

$ ansible-lint host_vars/aws-tasks-host.yml group_vars/wireguard.yml
Added ANSIBLE_ROLES_PATH=roles
WARNING  Overriding detected file kind 'yaml' with 'playbook' for given positional argument: host_vars/aws-tasks-host.yml
WARNING  Overriding detected file kind 'yaml' with 'playbook' for given positional argument: group_vars/wireguard.yml
WARNING  Listing 2 violation(s) that are fatal
syntax-check: A playbook must be a list of plays, got a <class 'ansible.parsing.yaml.objects.AnsibleMapping'> instead
ERROR! A playbook must be a list of plays, got a <class 'ansible.parsing.yaml.objects.AnsibleMapping'> instead

The error appears to be in '/path/to/group_vars/wireguard.yml': line 1, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


$ANSIBLE_VAULT;1.1;AES256
^ here


syntax-check: A playbook must be a list of plays, got a <class 'ansible.parsing.yaml.objects.AnsibleMapping'> instead
ERROR! A playbook must be a list of plays, got a <class 'ansible.parsing.yaml.objects.AnsibleMapping'> instead

The error appears to be in '/path/to/host_vars/aws-tasks-host.yml': line 1, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


$ANSIBLE_VAULT;1.1;AES256
^ here


You can skip specific rules or tags by adding them to your configuration file:
# .ansible-lint
warn_list:  # or 'skip_list' to silence them completely
  - syntax-check  # Ansible syntax check failed
Finished with 2 failure(s), 0 warning(s) on 2 files.

(Unlike #115, decryption appears working like previous versions)

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