Invoking multiple playbooks with include inside a block of Ansible

I am trying to have a block in Ansible which will invoke multiple playbooks using include if a specific flag is set. I am trying to achieve something similar to below:

- hosts: localhost tasks: - block: - include: script1.yml - include: script2.yml - include: script3.yml when: flag|bool

This snippet throws an error stating ERROR! unexpected parameter type in action: <type 'bool'>

Thanks in advance!

1 Answer

The plays can't be included in a block. Quoting from ansible.builtin.include Synopsis

Files with a list of plays can only be included at the top level.

As a result, only Play keywords can be applied. The condition when is not among them.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like