# roles and tasks reusability

**URL:** <https://forum.ansible.com/t/roles-and-tasks-reusability/24552>\
**Category:** Ansible Project\
**Created:** [May 23, 2017, 2:10pm UTC](https://forum.ansible.com/t/roles-and-tasks-reusability/24552 "2017-05-23T14:10:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lemaillet.efflam](https://avatars.discourse-cdn.com/v4/letter/l/f04885/32.png) [@lemaillet.efflam](https://forum.ansible.com/u/lemaillet.efflam)\
**Post date:** [May 23, 2017, 2:10pm UTC](https://forum.ansible.com/t/roles-and-tasks-reusability/24552/1 "2017-05-23T14:10:32Z")

</div>

Hello everyone,

I did not found a elegant way of sharing tasks list between roles.  
I explain my problem :

1 I have a first role in which i include tasks (IE create\_user.yml) so i put the file in my\_firt\_role/tasks/create\_user.yml  
2 I am writing an other role in which i would like to use the tasks create\_user.yml too

The only solutions i found to use it in both playbooks are :

hardcode the path of a common dir in my roles includes ( /var/ansible/common/create\_user.yml)  
duplicate the tasks in each playbook

I was expecting a way to configure tasks lookup directories (like role\_path for roles) in ansible.cfg  
I try also to add a role dependencies but it seems that the pulled roles are not sharing tasks to upper roles.

Am I missing an Ansible feature or good practice ?  
Any ideas to improve tasks re-usability and avoid duplication ?

Regards,

Efflam

---

<div class="post-metadata">

**Author:** ![lemaillet.efflam](https://avatars.discourse-cdn.com/v4/letter/l/f04885/32.png) [@lemaillet.efflam](https://forum.ansible.com/u/lemaillet.efflam)\
**Post date:** [May 23, 2017, 3:55pm UTC](https://forum.ansible.com/t/roles-and-tasks-reusability/24552/2 "2017-05-23T15:55:04Z")

</div>

I finaly found a workaround :

ansible seems to lookup in tasks directory (even symlinks)  
/etc/ansible/specific\_utils/  
├── utils\_stuff1.yml  
└── utils\_stuff2.yml  
/etc/ansible/common/  
├── common\_stuff1.yml  
└── common\_stuff2.yml

/path/to/your/ansible/workdir  
├── tasks → …/…/…/…/etc/ansible/common  
└── your\_role  
└── tasks  
├── main.yml

└── tasks → …/…/…/…/…/…/…/etc/ansible/specific\_utils

---

<div class="post-metadata">

**Author:** ![Daniel\_JD](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Daniel\_JD](https://forum.ansible.com/u/Daniel_JD)\
**Post date:** [May 30, 2017, 5:37am UTC](https://forum.ansible.com/t/roles-and-tasks-reusability/24552/3 "2017-05-30T05:37:55Z")

</div>

You could use the include\_role module like this:

include\_role:  
name: my\_flirt\_role  
tasks\_from: create\_user
