import_tasks and import_playbook in a single .yml file

390 views
Skip to first unread message

ktesr...@gmail.com

unread,
Feb 16, 2018, 2:24:20 PM2/16/18
to Ansible Project
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.

Brian Coca

unread,
Feb 19, 2018, 6:40:28 PM2/19/18
to Ansible Project
like this:

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

- import_playbook: myplaybook.yml

--
----------
Brian Coca

ktesr...@gmail.com

unread,
Feb 20, 2018, 9:28:19 AM2/20/18
to Ansible Project
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.

Brian Coca

unread,
Feb 20, 2018, 9:44:38 AM2/20/18
to Ansible Project
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.


--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages