Interview Prep/Ansible/YAML, Syntax and Jinja2 Errors

`ERROR! A malformed block was encountered while loading tasks: {...} should be a list or None but is <class 'ansible.parsing.yaml.objects.AnsibleMapping'>`

IntermediateTroubleshootingYAML, Syntax and Jinja2 Errors
Answer

Likely causes → A tasks file (tasks/main.yml, or a file loaded with include_tasks/import_tasks) holds a mapping at the top level instead of a list. This usually means the leading - on the first task is missing. A related mistake is putting a whole play (hosts:, tasks:) into a file that is included as tasks.

Diagnose → Open the file the error names. Its first line must be - name: ..., not name: ....

Fix → Turn the content into a list of tasks. If the file is really a play, load it with import_playbook at the playbook level instead of import_tasks.

Prevent → Keep a clear split: playbooks/*.yml hold plays, and tasks/*.yml hold task lists only.

All Ansible questions Roadmap: Ansible

More on YAML, Syntax and Jinja2 Errors