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

Determine if passed arguments are playbooks or not #2912

Merged
merged 1 commit into from Jan 19, 2023
Merged

Conversation

ssbarnea
Copy link
Member

@ssbarnea ssbarnea commented Jan 18, 2023

From now on, ansible-lint will no longer assume that a passed argument
must be a playbook. This addressed multiple bug reports where people
were confused that the linter reported errors when they passed a
taskfile as an argument.

The downside is that an invalid playbook that is a valid YAML file
might not raise an error and just report a warning and be treated as
a generic yaml file.

Fixes: #2892
Fixes: #2888

@github-actions github-actions bot added the bug label Jan 18, 2023
@ssbarnea ssbarnea added enhancement feedback-needed Divergent oppinions, additional feedback is desired in order to unblock it. and removed bug labels Jan 18, 2023
@cidrblock
Copy link
Contributor

Should we do detection similar to the extension? https://github.com/ansible/vscode-ansible#without-file-inspection

as a backup to a playbook that isn't valid but is intended to be a playbook?

@konstruktoid
Copy link
Contributor

It looks sane, but I'm having trouble testing it, see #2909

@konstruktoid
Copy link
Contributor

konstruktoid commented Jan 19, 2023

LGTM, but I didnt run the automated tests (https://github.com/ansible/ansible-lint/actions/runs/3958630702)

vagrant@ubuntu-jammy:~/ansible-lint$ pip3 install -U .
Defaulting to user installation because normal site-packages is not writeable
Processing /home/vagrant/ansible-lint
[...]
Successfully installed ansible-lint-6.11.1.dev4
vagrant@ubuntu-jammy:~/ansible-lint$ cd ..
vagrant@ubuntu-jammy:~$ git clone https://github.com/konstruktoid/ansible-event-otx
[...]
vagrant@ubuntu-jammy:~$ cd ansible-event-otx/
vagrant@ubuntu-jammy:~/ansible-event-otx$ ansible-lint .
WARNING  Passed '.github/FUNDING.yml' positional argument was identified as generic 'yaml' file kind.
WARNING  Passed '.github/workflows/codeql.yml' positional argument was identified as generic 'yaml' file kind.
WARNING  Passed '.github/workflows/issues.yml' positional argument was identified as generic 'yaml' file kind.
WARNING  Passed '.github/workflows/slsa.yml' positional argument was identified as generic 'yaml' file kind.

Passed with production profile: 0 failure(s), 0 warning(s) on 1 files.
You are using a pre-release version of ansible-lint.
vagrant@ubuntu-jammy:~/ansible-event-otx$ ansible-lint otx.yml

Passed with production profile: 0 failure(s), 0 warning(s) on 1 files.
You are using a pre-release version of ansible-lint.
vagrant@ubuntu-jammy:~/ansible-event-otx$ ansible-lint ../ansible-lint/playbook.yml

Passed with production profile: 0 failure(s), 0 warning(s) on 0 files.
You are using a pre-release version of ansible-lint.
vagrant@ubuntu-jammy:~/ansible-event-otx$ ansible-lint ../ansible-lint/examples/broken/yaml-with-tabs/invalid-due-tabs.yaml
Failed to load YAML file
vagrant@ubuntu-jammy:~/ansible-event-otx$ ansible-lint ../ansible-lint/examples/playbooks/rule-no-tabs.yml

Passed with production profile: 0 failure(s), 0 warning(s) on 0 files.
You are using a pre-release version of ansible-lint.
vagrant@ubuntu-jammy:~/ansible-event-otx$ ansible-lint -v otx.yml
INFO     Set ANSIBLE_LIBRARY=/home/vagrant/.cache/ansible-compat/ad5374/modules:/home/vagrant/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/vagrant/.cache/ansible-compat/ad5374/collections:/home/vagrant/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/home/vagrant/.cache/ansible-compat/ad5374/roles:/home/vagrant/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles

Passed with production profile: 0 failure(s), 0 warning(s) on 1 files.
You are using a pre-release version of ansible-lint.
vagrant@ubuntu-jammy:~/ansible-event-otx$ ansible-lint -v otx_ufw.yml
INFO     Set ANSIBLE_LIBRARY=/home/vagrant/.cache/ansible-compat/ad5374/modules:/home/vagrant/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/vagrant/.cache/ansible-compat/ad5374/collections:/home/vagrant/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/home/vagrant/.cache/ansible-compat/ad5374/roles:/home/vagrant/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Executing syntax check on otx_ufw.yml (0.62s)
WARNING  Listing 1 violation(s) that are fatal
syntax-check[specific]: couldn't resolve module/action 'community.general.ufw'. This often indicates a misspelling, missing collection, or incorrect module path.
otx_ufw.yml:5:7

You can skip specific rules or tags by adding them to your configuration file:
# .config/ansible-lint.yml
warn_list:  # or 'skip_list' to silence them completely
  - syntax-check[specific]  # Ansible syntax check failed.

                  Rule Violation Summary
 count tag                    profile rule associated tags
     1 syntax-check[specific] min     core

Failed after : 1 failure(s), 0 warning(s) on 1 files.
You are using a pre-release version of ansible-lint.
vagrant@ubuntu-jammy:~/ansible-event-otx$ ansible-lint ../ansible-lint/examples/rulebooks/rulebook.yml

Passed with production profile: 0 failure(s), 0 warning(s) on 0 files.

Fails on:

~/ansible-lint$ ansible-lint examples/playbooks/rulebook.yml 
WARNING  Listing 1 violation(s) that are fatal
syntax-check[specific]: 'sources' is not a valid attribute for a Play
examples/playbooks/rulebook.yml:4:3

You can skip specific rules or tags by adding them to your configuration file:
# .config/ansible-lint.yml
warn_list:  # or 'skip_list' to silence them completely
  - syntax-check[specific]  # Ansible syntax check failed.

                  Rule Violation Summary                   
 count tag                    profile rule associated tags 
     1 syntax-check[specific] min     core                 

Failed after : 1 failure(s), 0 warning(s) on 1 files.

Passes on:

$ ansible-lint examples/rulebooks/rulebook.yml

Passed with production profile: 0 failure(s), 0 warning(s) on 1 files.

@ssbarnea ssbarnea force-pushed the fix/rulebook branch 3 times, most recently from 831ef53 to eb2acce Compare January 19, 2023 18:17
@ssbarnea ssbarnea marked this pull request as ready for review January 19, 2023 18:18
@ssbarnea ssbarnea requested review from a team as code owners January 19, 2023 18:18
@ssbarnea ssbarnea removed bug feedback-needed Divergent oppinions, additional feedback is desired in order to unblock it. labels Jan 19, 2023
From now on, ansible-lint will no longer assume that a passed argument
must be a playbook. This addressed multiple bug reports where people
were confused that the linter reported errors when they passed a
taskfile as an argument.

The downside is that an invalid playbook that is a valid YAML file
might not raise an error and just report a warning and be treated as
a generic yaml file.

Fixes: #2892
@github-actions github-actions bot added the bug label Jan 19, 2023
@ssbarnea ssbarnea removed the bug label Jan 19, 2023
@ssbarnea ssbarnea merged commit 497bae9 into main Jan 19, 2023
@ssbarnea ssbarnea deleted the fix/rulebook branch January 19, 2023 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants