You cannot import a playbook anywhere inside a play - importing a playbook is a
play of its own.
If you want to run the imported playbook first, try:
- name: this play runs ‘another.yml' on the hosts it defines
import_playbook: another.yml
- name: this play runs two roles on all hosts in the mywebservers group
hosts: mywebservers
gather_facts: yes
roles:
- role: testrole1
tags: testrole1
- role: testrole2
tags: othertag
If you want to run the roles first, reverse the order of the two plays.
You can also review the general documentation on importing and including at
https://docs.ansible.com/ansible/devel/user_guide/playbooks_reuse.html
<https://docs.ansible.com/ansible/devel/user_guide/playbooks_reuse.html>. You
may want to edit “another.yml” to make it a tasks file instead of a playbook
for greater flexibility.
Hope this helps,
Alicia
> On Jan 22, 2020, at 3:24 PM, Xinhuan Zheng <[email protected]> wrote:
>
>
> Take a look again at the example in
> https://docs.ansible.com/ansible/latest/modules/import_playbook_module.html
> <https://docs.ansible.com/ansible/latest/modules/import_playbook_module.html>.
>
> To me it does not know where
>
>
> roles:
> - role: testrole1
> tags: testrole1
>
> belongs. Should it be
>
> - hosts: mywebservers
> gather_facts: yes
>
> roles:
> - role: testrole1
> tags: testrole1
>
> #- import_playbook: another.yml
>
> i.e. those roles are related to mywebservers? Or are they related to
> all hosts as defined in another.yml?
>
>
>
> testrole1 belongs to mywebservers. It isn't related to all hosts as defined
> in another.yml file. However, another.yml file needs to be called first. I
> tried using pre_tasks with import_playbook. It doesn't work either. I also
> tried using include, still not working. Since another.yml file contains a
> list of roles, it is supposed to be import_playbook, but I'm not sure how to
> make import_playbook working in current_playbook.yml file.
>
> Thanks again,
>
> - Xinhuan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/ea2a316c-0d8e-4641-9e94-d10e708b3ea5%40googlegroups.com
>
> <https://groups.google.com/d/msgid/ansible-project/ea2a316c-0d8e-4641-9e94-d10e708b3ea5%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/B1AFBEEC-7631-423A-9250-FE6E4753C2F9%40redhat.com.