Import/Include a Single task from one play book to another play book.

Hi All,

Not sure whether it is possible, but let me raise the question, it is possible to import/include a single task for one play book to another play book rather than importing the entire play book.e.g

common.yml

  • task1
    tags: T1

  • task2
    tags: T2

  • task3
    tags: T3

one.yml
include common.yml --tag T1

two.yml
include common.yml --tag T2

include common.yml --tag T3

From,
Vino.B

Hi Vino,

Yes, it is possible you have to include your child playbook to add in your parent playbook.

– include your_playbook.yml

this will run after your parent playbook get executed.

Thanks & Regards
Sumit Sahay

no, you cannot pass 'run this tag' to includes.

Hi All,

I was able to find the solution as this was stated in the ansible documentation

And import/include statements:

- import_tasks: foo.yml
  tags: [web,foo]

or:

- include_tasks: foo.yml
  tags: [web,foo]

All of these apply the specified tags to EACH task inside the play, included file, or role, so that these tasks can be selectively run when the playbook is invoked with the corresponding tags.

import_X applies the tags to the imported tasks, include_X has the
tags applied to itself, but not to the included tasks (we plan update
with feature to allow for this).