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

Empty task "-" crashes ansible-lint #468

Closed
qinqon opened this issue Jan 18, 2019 · 4 comments · Fixed by #1048
Closed

Empty task "-" crashes ansible-lint #468

qinqon opened this issue Jan 18, 2019 · 4 comments · Fixed by #1048
Assignees
Labels

Comments

@qinqon
Copy link

qinqon commented Jan 18, 2019

Issue Type

  • Bug report

Ansible and Ansible Lint details

ansible --version
ansible 2.7.5
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ellorent/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ellorent/.local/lib/python2.7/site-packages/ansible
  executable location = /home/ellorent/.local/bin/ansible
  python version = 2.7.15 (default, Oct 15 2018, 15:24:06) [GCC 8.1.1 20180712 (Red Hat 8.1.1-5)]

ansible-lint --version
ansible-lint 3.4.23
  • ansible installation method: one of source, pip, OS package
    pip install --user ansible
  • ansible-lint installation method: one of source, pip, OS package
    pre-commit call with git commit -a --amend

Desired Behaviour

If you have a list of tasks with an empty want if have to report you as failure

  • name: foobar
    debug:
    msg: Hello world

Actual Behaviour (Bug report only)

Instead of failing with a proper message it crashes
Traceback (most recent call last):
File "/home/ellorent/.cache/pre-commit/repoHkh3h8/py_env-python2/bin/ansible-lint", line 11, in
sys.exit(main())
File "/home/ellorent/.cache/pre-commit/repoHkh3h8/py_env-python2/lib/python2.7/site-packages/ansiblelint/main.py", line 176, in main
matches.extend(runner.run())
File "/home/ellorent/.cache/pre-commit/repoHkh3h8/py_env-python2/lib/python2.7/site-packages/ansiblelint/init.py", line 229, in run
for child in ansiblelint.utils.find_children(arg, self.playbook_dir):
File "/home/ellorent/.cache/pre-commit/repoHkh3h8/py_env-python2/lib/python2.7/site-packages/ansiblelint/utils.py", line 169, in find_children
items = _playbook_items(playbook_ds)
File "/home/ellorent/.cache/pre-commit/repoHkh3h8/py_env-python2/lib/python2.7/site-packages/ansiblelint/utils.py", line 154, in _playbook_items
return [item for play in pb_data for item in play.items()]
AttributeError: 'NoneType' object has no attribute 'items'

@awcrosby
Copy link
Contributor

We can make a change to prevent ansible-lint from crashing on an empty task (ansible and yamllint don’t throw an error on this example)

I’m not sure how useful it would be, but we could have a line-based rule to check for a line equal to -

@qinqon
Copy link
Author

qinqon commented Jan 31, 2019

That sounds good.

@besmirzanaj
Copy link

facing this error and the verbosity is useless. At least pinpoint which file has the error and if possible which task line

@angelos-se
Copy link

This is very desirable function.

I'm trying to check my playbook using ansible-lint now, but I'm hit with this error on first run. Any tips on quickly locating the offending role / tasks?

ssbarnea added a commit that referenced this issue Sep 10, 2020
As ansible allows tasks to be None, we should also avoid crashing when
encountering them.

Includes regression prevention by assuring we can parse files
with empty tasks.

Fixes: #468
@ssbarnea ssbarnea self-assigned this Sep 10, 2020
ssbarnea added a commit that referenced this issue Sep 10, 2020
As ansible allows tasks to be None, we should also avoid crashing when
encountering them.

Includes regression prevention by assuring we can parse files
with empty tasks.

Fixes: #468
ssbarnea added a commit that referenced this issue Sep 10, 2020
As ansible allows tasks to be None, we should also avoid crashing when
encountering them.

Includes regression prevention by assuring we can parse files
with empty tasks.

Fixes: #468
ssbarnea added a commit that referenced this issue Oct 2, 2020
As ansible allows tasks to be None, we should also avoid crashing when
encountering them.

Includes regression prevention by assuring we can parse files
with empty tasks.

Fixes: #468
ssbarnea added a commit that referenced this issue Nov 2, 2020
As ansible allows tasks to be None, we should also avoid crashing when
encountering them.

Includes regression prevention by assuring we can parse files
with empty tasks.

Fixes: #468
rhosqeauto pushed a commit to redhat-openstack/infrared that referenced this issue Jul 16, 2021
Version bump to fix crashes on empty tasks [1]

* ansible-lint has been bumped to 4.3.0
* Move most of tasks from skip_list to warn_list allowing to see them on
  every task.
* 106,201,206,207,208,305,601 exceptions are added to warn_list. All
  of these exceptions were not present in ansible-lint < 4.3.0. All of
  them can be seen in the jobs.

[1] ansible/ansible-lint#468

Change-Id: I1ea6c2c6776dc5c07925f13bfa968dfeca74f5ca
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.

5 participants