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

import_task swallows AnsibleParserError #68605

Closed
mdaniel opened this issue Apr 1, 2020 · 3 comments · Fixed by #72677
Closed

import_task swallows AnsibleParserError #68605

mdaniel opened this issue Apr 1, 2020 · 3 comments · Fixed by #72677
Labels
affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. P3 Priority 3 - Approved, No Time Limitation python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.

Comments

@mdaniel
Copy link
Contributor

mdaniel commented Apr 1, 2020

SUMMARY

A malformed list item in an included task file yields a cryptic message

ISSUE TYPE
  • Bug Report
COMPONENT NAME

lib/ansible/cli/scripts/ansible_cli_stub.py

ANSIBLE VERSION

Confirmed as of c888035

ansible 2.10.0.dev0
  config file = None
  configured module search path = ['/usr/share/ansible/plugins/modules']
  ansible python module location = /proj/ansible/ansible/venv/lib/python3.7/site-packages/ansible_base-2.10.0.dev0-py3.7.egg/ansible
  executable location = /proj/ansible/ansible/venv/bin/ansible
  python version = 3.7.7 (default, Mar 11 2020, 11:44:20) [GCC 9.2.1 20191008]
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
  • bug.yml
---
- oops
  • pb.yml
- hosts: all
  gather_facts: no
  tasks:
  - include_tasks: bug.yml
EXPECTED RESULTS
$ ansible-playbook -i localhost, -c local pb.yml
ERROR! Traceback (most recent call last):
  File "/proj/ansible/ansible/lib/ansible/playbook/block.py", line 130, in _load_block
    use_handlers=self._use_handlers,
  File "/proj/ansible/ansible/lib/ansible/playbook/helpers.py", line 106, in load_list_of_tasks
    raise AnsibleAssertionError('The ds (%s) should be a dict but was a %s' % (ds, type(ds)))
ansible.errors.AnsibleAssertionError: The ds (['oops']) should be a dict but was a <class 'list'>

or something similar, because just eating the AnsibleParserError makes tracking down the erroneous list item harder than necessary

ACTUAL RESULTS
$ ansible-playbook -i localhost, -c local -vvvvvvvvv pb.yml
ansible-playbook 2.10.0.dev0
  config file = None
  configured module search path = ['/usr/share/ansible/plugins/modules']
  ansible python module location = /proj/ansible/ansible/lib/ansible
  executable location = /proj/ansible/ansible/venv/bin/ansible-playbook
  python version = 3.7.7 (default, Mar 11 2020, 11:44:20) [GCC 9.2.1 20191008]
No config file found; using defaults
setting up inventory plugins
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
statically imported: /proj/ansible/ansible/bug.yml
ERROR! A malformed block was encountered while loading a block

and the same outcome when run with ANSIBLE_DEBUG=1 which was especially surprising

$ ANSIBLE_DEBUG=1 ansible-playbook -i localhost, -c local -vvvvvvvvv pb.yml
## snip
 22539 1585707905.71204: Loading BecomeModule 'sudo' from /proj/ansible/ansible/lib/ansible/plugins/become/sudo.py (found_in_cache=False, class_only=True)
 22539 1585707905.71232: Loading data from /proj/ansible/ansible/bug0.yml
 22539 1585707905.71591: in VariableManager get_vars()
 22539 1585707905.71621: done with get_vars()
 22539 1585707905.71634: Loading data from /proj/ansible/ansible/bug00.yml
statically imported: /proj/ansible/ansible/bug.yml
 22539 1585707905.71686: RUNNING CLEANUP
ERROR! A malformed block was encountered while loading a block
@ansibot
Copy link
Contributor

ansibot commented Apr 1, 2020

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback. labels Apr 1, 2020
@sivel sivel added needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels Apr 21, 2020
@felixfontein
Copy link
Contributor

This isn't just related to import_task, but happens in general:

- hosts: localhost
  tasks:
    - debug msg=hi

@felixfontein
Copy link
Contributor

See https://app.shippable.com/github/ansible-collections/ansible.posix/runs/456/27/console for a real-life example - every CI run here failed with ERROR! A malformed block was encountered while loading a block without providing any more information. Since the test was just re-enabled in the most recent commit, it took some time to spot the error.

sivel added a commit to sivel/ansible that referenced this issue Nov 19, 2020
jborean93 pushed a commit that referenced this issue Nov 19, 2020
* Add orig_exc context to error messages. Fixes #68605

* Fix string formatting
@ansible ansible locked and limited conversation to collaborators Dec 17, 2020
@sivel sivel removed the needs_verified This issue needs to be verified/reproduced by maintainer label Feb 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. P3 Priority 3 - Approved, No Time Limitation python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants