Ansible - import_playbook module

Let's say you have a playbook named main.yml, and in this playbook, you want to run the foo.yml and bar.yml playbooks. This could be done using:

IMPORTANT - import_playbook cannot be used in the tasks plugin

For example, this would not work. If you want to include the tasks in a playbook during tasks execution, the include_role module or include_tasks module can be used instead.

- hosts: all
    import_playbook: foo.yml


IMPORTANT - The when parameter cannot be used with import_playbook.

Attempting to use the when parameter, like this, would return a fatal error. For this reason, the include_role module or include_tasks module can be used instead, as the when parameter can be used with these modules.

- import_playbook: foo.yml
  when: foo == bar


In this example, the child.yml playbook is imported.

- name: import 'foo.yml'
  import_playbook: foo.yml


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 524b4 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |