Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Invalid task file syntax in imported tasks prevents all non-playbook checks from running #2057

Closed
wbh1 opened this issue Mar 31, 2022 · 3 comments · Fixed by #2058
Closed
Assignees
Labels

Comments

@wbh1
Copy link
Contributor

wbh1 commented Mar 31, 2022

Summary

If there's an invalid task file anywhere in the list of files that ansible-lint checks, it silently fails to do any linting besides syntax-check on playbooks.

Issue Type
  • Bug Report
Ansible and Ansible Lint details
ansible --version
ansible [core 2.12.4]
  config file = /Users/whegedus/.ansible.cfg
  configured module search path = ['/Users/whegedus/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/whegedus/bits/ansible_collections:/Users/whegedus/github:/Users/whegedus/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.10 (main, Jan 15 2022, 11:48:00) [Clang 13.0.0 (clang-1300.0.29.3)]
  jinja version = 2.10.1
  libyaml = False


ansible-lint --version
ansible-lint 6.0.2 using ansible 2.12.4
  • ansible installation method: pip
  • ansible-lint installation method: pip
OS / ENVIRONMENT

Tested on MacOS Monterey and Debian 10

STEPS TO REPRODUCE

Put invalid syntax in an imported/included file and observe with verbose logging that only playbooks are linted.

See https://github.com/wbh1/ansible-lint-test for a working example.

Desired Behavior

ansible-lint alerts me to the the invalid syntax. This is what happens if the invalid block is in tasks/main.yml, but does not happen on imported tasks.

This is what happens when the invalid syntax block is commented out:

ansible-lint -vvv
WARNING: PATH altered to include /usr/local/opt/python@3.9/bin
DEBUG    Logging initialized to level 10
DEBUG    Options: Namespace(cache_dir='/Users/whegedus/.cache/ansible-compat/f23de3', colored=True, configured=True, cwd=PosixPath('/Users/whegedus/github/wbh1/ansible-lint-test'), display_relative_path=True, exclude_paths=['.cache', '.git', '.hg', '.svn', '.tox'], format='rich', lintables=[], listrules=False, listtags=False, write=False, parseable=False, quiet=0, rulesdirs=['/usr/local/lib/python3.9/site-packages/ansiblelint/rules'], skip_list=[], tags=[], verbosity=3, warn_list=['experimental', 'role-name'], kinds=[{'jinja2': '**/*.j2'}, {'jinja2': '**/*.j2.*'}, {'text': '**/templates/**/*.*'}, {'inventory': '**/inventory/**.yml'}, {'requirements': '**/meta/requirements.yml'}, {'galaxy': '**/galaxy.yml'}, {'reno': '**/releasenotes/*/*.{yaml,yml}'}, {'playbook': '**/playbooks/*.{yml,yaml}'}, {'playbook': '**/*playbook*.{yml,yaml}'}, {'role': '**/roles/*/'}, {'tasks': '**/tasks/**/*.{yaml,yml}'}, {'handlers': '**/handlers/*.{yaml,yml}'}, {'vars': '**/{host_vars,group_vars,vars,defaults}/**/*.{yaml,yml}'}, {'meta': '**/meta/main.{yaml,yml}'}, {'yaml': '.config/molecule/config.{yaml,yml}'}, {'requirements': '**/molecule/*/{collections,requirements}.{yaml,yml}'}, {'yaml': '**/molecule/*/{base,molecule}.{yaml,yml}'}, {'requirements': '**/requirements.yml'}, {'playbook': '**/molecule/*/*.{yaml,yml}'}, {'yaml': '**/{.ansible-lint,.yamllint}'}, {'yaml': '**/*.{yaml,yml}'}, {'yaml': '**/.*.{yaml,yml}'}], mock_modules=[], mock_roles=[], loop_var_prefix=None, var_naming_pattern=None, offline=None, project_dir='.', extra_vars=None, enable_list=[], skip_action_validation=True, rules={}, progressive=False, rulesdir=[], use_default_rules=False, config_file=None, version=False)
DEBUG    /Users/whegedus/github/wbh1/ansible-lint-test
INFO     Set ANSIBLE_LIBRARY=/Users/whegedus/.cache/ansible-compat/f23de3/modules:/Users/whegedus/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/Users/whegedus/.cache/ansible-compat/f23de3/collections:/Users/whegedus/bits/ansible_collections:/Users/whegedus/github:/Users/whegedus/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/Users/whegedus/.cache/ansible-compat/f23de3/roles:roles:/Users/whegedus/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
DEBUG    Loading rules from /usr/local/lib/python3.9/site-packages/ansiblelint/rules
DEBUG    Effective yamllint rules used: {'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error'}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': False, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}}
INFO     Looking up for files, excluding .cache|.git|.hg|.svn|.tox ...
DEBUG    Added role: roles/cleanup (role)
INFO     Looking up for files, excluding .cache|.git|.hg|.svn|.tox ...
INFO     Executing syntax check on playbooks/test.yml (2.10s)
DEBUG    Examining playbooks/test.yml of type playbook
DEBUG    Examining roles/cleanup/tasks/uninstall.yml of type tasks
DEBUG    Examining roles/cleanup of type role
DEBUG    Examining roles/cleanup/tasks/main.yml of type tasks
WARNING  Listing 1 violation(s) that are fatal
fqcn-builtins: Use FQCN for builtin actions.
roles/cleanup/tasks/uninstall.yml:2 Task/Handler: uninstall something

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
  - fqcn-builtins  # Use FQCN for builtin actions.

Finished with 1 failure(s), 0 warning(s) on 4 files.
Actual Behavior
ansible-lint -vvv
WARNING: PATH altered to include /usr/local/opt/python@3.9/bin
DEBUG    Logging initialized to level 10
DEBUG    Options: Namespace(cache_dir='/Users/whegedus/.cache/ansible-compat/f23de3', colored=True, configured=True, cwd=PosixPath('/Users/whegedus/github/wbh1/ansible-lint-test'), display_relative_path=True, exclude_paths=['.cache', '.git', '.hg', '.svn', '.tox'], format='rich', lintables=[], listrules=False, listtags=False, write=False, parseable=False, quiet=0, rulesdirs=['/usr/local/lib/python3.9/site-packages/ansiblelint/rules'], skip_list=[], tags=[], verbosity=3, warn_list=['experimental', 'role-name'], kinds=[{'jinja2': '**/*.j2'}, {'jinja2': '**/*.j2.*'}, {'text': '**/templates/**/*.*'}, {'inventory': '**/inventory/**.yml'}, {'requirements': '**/meta/requirements.yml'}, {'galaxy': '**/galaxy.yml'}, {'reno': '**/releasenotes/*/*.{yaml,yml}'}, {'playbook': '**/playbooks/*.{yml,yaml}'}, {'playbook': '**/*playbook*.{yml,yaml}'}, {'role': '**/roles/*/'}, {'tasks': '**/tasks/**/*.{yaml,yml}'}, {'handlers': '**/handlers/*.{yaml,yml}'}, {'vars': '**/{host_vars,group_vars,vars,defaults}/**/*.{yaml,yml}'}, {'meta': '**/meta/main.{yaml,yml}'}, {'yaml': '.config/molecule/config.{yaml,yml}'}, {'requirements': '**/molecule/*/{collections,requirements}.{yaml,yml}'}, {'yaml': '**/molecule/*/{base,molecule}.{yaml,yml}'}, {'requirements': '**/requirements.yml'}, {'playbook': '**/molecule/*/*.{yaml,yml}'}, {'yaml': '**/{.ansible-lint,.yamllint}'}, {'yaml': '**/*.{yaml,yml}'}, {'yaml': '**/.*.{yaml,yml}'}], mock_modules=[], mock_roles=[], loop_var_prefix=None, var_naming_pattern=None, offline=None, project_dir='.', extra_vars=None, enable_list=[], skip_action_validation=True, rules={}, progressive=False, rulesdir=[], use_default_rules=False, config_file=None, version=False)
DEBUG    /Users/whegedus/github/wbh1/ansible-lint-test
INFO     Set ANSIBLE_LIBRARY=/Users/whegedus/.cache/ansible-compat/f23de3/modules:/Users/whegedus/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/Users/whegedus/.cache/ansible-compat/f23de3/collections:/Users/whegedus/bits/ansible_collections:/Users/whegedus/github:/Users/whegedus/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/Users/whegedus/.cache/ansible-compat/f23de3/roles:roles:/Users/whegedus/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
DEBUG    Loading rules from /usr/local/lib/python3.9/site-packages/ansiblelint/rules
DEBUG    Effective yamllint rules used: {'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error'}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': False, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}}
INFO     Looking up for files, excluding .cache|.git|.hg|.svn|.tox ...
DEBUG    Added role: roles/cleanup (role)
INFO     Looking up for files, excluding .cache|.git|.hg|.svn|.tox ...
INFO     Executing syntax check on playbooks/test.yml (2.27s)

minimum complete verifiable example: https://github.com/wbh1/ansible-lint-test

@wbh1 wbh1 added bug new Triage required labels Mar 31, 2022
@wbh1
Copy link
Contributor Author

wbh1 commented Mar 31, 2022

This behavior was introduced in #1984 in which the error no longer is wrapped and does not get propagated to the user. Confirmed that changing to raise SystemExit(exc) from exc presents the error as expected.

@ssbarnea ssbarnea self-assigned this Apr 6, 2022
@ssbarnea ssbarnea removed the new Triage required label Apr 6, 2022
@rndmh3ro
Copy link

rndmh3ro commented Jul 7, 2022

This problem still occurs on v6.3.0. The linked demo-repository still fails silently.

@wbh1
Copy link
Contributor Author

wbh1 commented Jul 9, 2022

@rndmh3ro I am not able to reproduce. Could you share more information as to how you are seeing this?

This is the output I just got with a fresh install of v6.3.0 of ansible-lint using that demo repository.

<... omitted ...>
The offending line appears to be:


handlers:
^ hereansible-lint --version
WARNING: PATH altered to include /usr/local/opt/python@3.9/bin
ansible-lint 6.3.0 using ansible 2.12.6

@ansible ansible locked and limited conversation to collaborators Jul 13, 2022
@ssbarnea ssbarnea converted this issue into discussion #2236 Jul 13, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants