import_tasks and import_playbook in a single .yml file

Team,

Can i have import_tasks and import_playbook in one .yml file, i have a sequence of tasks to be executed first and then a playbook and then a task.

Please share if we have any example of that kind.

Thanks.

like this:

- hosts: <whatever>
  tasks:
     - import_tasks: mytasks.yml

- import_playbook: myplaybook.yml

Thank you Brian,

does the scope of variables change when execution is switched from task to playbook.

I have a password variable in task but it is empty when it comes to execution of playbook

Thanks.

The tasks are ALWAYS inside a play so tasks are always in play scope,
that of which play they were in, either directly, through role or
include/import.

A 'playbook' is generally a list of plays, though some people call
'task list files' playbooks also ... which leads to confusion, but for
`import_playbooks` only the former definition is valid.

Each play is in their own scope, the data shared between plays comes
from either extra_vars or inventory, the latter being able to also
keep facts+host scoped vars across plays.

'non host vars' or 'play vars' defined in each play are lost once the play ends.