# import\_tasks and import\_playbook in a single .yml file

**URL:** <https://forum.ansible.com/t/import-tasks-and-import-playbook-in-a-single-yml-file/26766>\
**Category:** Ansible Project\
**Created:** [February 16, 2018, 7:24pm UTC](https://forum.ansible.com/t/import-tasks-and-import-playbook-in-a-single-yml-file/26766 "2018-02-16T19:24:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktesr123456](https://avatars.discourse-cdn.com/v4/letter/k/4da419/32.png) [@ktesr123456](https://forum.ansible.com/u/ktesr123456)\
**Post date:** [February 16, 2018, 7:24pm UTC](https://forum.ansible.com/t/import-tasks-and-import-playbook-in-a-single-yml-file/26766/1 "2018-02-16T19:24:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 19, 2018, 11:40pm UTC](https://forum.ansible.com/t/import-tasks-and-import-playbook-in-a-single-yml-file/26766/2 "2018-02-19T23:40:13Z")

</div>

like this:

- hosts: \<whatever\>  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- import\_tasks: mytasks.yml

- import\_playbook: myplaybook.yml

---

<div class="post-metadata">

**Author:** ![ktesr123456](https://avatars.discourse-cdn.com/v4/letter/k/4da419/32.png) [@ktesr123456](https://forum.ansible.com/u/ktesr123456)\
**Post date:** [February 20, 2018, 2:28pm UTC](https://forum.ansible.com/t/import-tasks-and-import-playbook-in-a-single-yml-file/26766/3 "2018-02-20T14:28:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 20, 2018, 2:44pm UTC](https://forum.ansible.com/t/import-tasks-and-import-playbook-in-a-single-yml-file/26766/4 "2018-02-20T14:44:22Z")

</div>

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.
