include tasks from another role in ansible playbook

Question:

I’m designing a kind of playbook lib with individual tasks

so in the usual roles repo, I have something like:

my main.yml in custom_stuff_workflow then contain something like:

and this one in the other workflow:

I can’t find a way to do it in a natural way:
one way that worked was having all tasks in a single role and tagging the relevant tasks while including a custom_stuff_workflow

The problem I have with that is that tags cannot be set in the calling playbook: it’s only to be set at command line
as I’m distributing this ansible repo with many people in the company, I can’t rely on command line invocations (it would be nice to have a #! header in yml to be processed by ansible-playbook command)

I could also copy the relevant tasks (inside common in the above tree) in each workflow, but I don’t want to repeat them around

Can someone see a solution to achieve what I’d like without repeating the tasks over different roles?

I guess the corner stone of my problem is that I define tasks as individual and it looks not natural in ansible…

Thanks a lot

PS: note that the tasks in the workflow have to be done in specific order and the only natural steps to abstract would be the login and save/logout

Answer:

Just incase someone else bumps into this, version 2.2 of Ansible now has include_role.You can now do something like this.

Check out the documentation here.

Leave a Reply