Ansible include scenario with list of plays or tasks

Are you trying to use include in your playbook and coming across a error somthing like “A playbook must be a list of plays”. That means you are at right url.

include help you to Includes a file with a list of plays or tasks to be executed in the current playbook. Files with a list of plays can only be included at the top level. Lists of tasks can only be included where tasks normally run (in play).

With include on the task level Ansible expects a file with tasks only, not a full playbook.

With include on the task level Ansible expects a file with tasks only, not a full playbook.

With include on the play level Ansible expects a playbook with hosts/tasks spec. i.e full playbook.

Example of include calling common tasks.

Some of more example using Condition

Rajesh Kumar
Total Page Visits: 111 - Today Page Visits: 3