# Different yml tasks files  within a role

**URL:** <https://forum.ansible.com/t/different-yml-tasks-files-within-a-role/13825>\
**Category:** Ansible Project\
**Created:** [November 1, 2013, 6:45pm UTC](https://forum.ansible.com/t/different-yml-tasks-files-within-a-role/13825 "2013-11-01T18:45:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Narcis\_Pillao\_Figuer](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@Narcis\_Pillao\_Figuer](https://forum.ansible.com/u/Narcis_Pillao_Figuer)\
**Post date:** [November 1, 2013, 6:45pm UTC](https://forum.ansible.com/t/different-yml-tasks-files-within-a-role/13825/1 "2013-11-01T18:45:06Z")

</div>

Hi,

I’m not sure if some else has already asked it because it is quiet necessary but I did not find that thread at least.

The point is have a mysql role, but I need to separate task in different files, currently I have a main.yml file which do all common tasks, but I need to do different things for master and slaves:

setup.yml

- hosts: databases  
roles:
- { role: mysql, mysql\_root\_password: XXXXXX, tags: mysql }

but now I would need do something like:

- hosts: master
- include: roles/mysql/tasks/master.yml

I appreciate your time and your tips.

Thanks !

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [November 1, 2013, 8:12pm UTC](https://forum.ansible.com/t/different-yml-tasks-files-within-a-role/13825/2 "2013-11-01T20:12:12Z")

</div>

I would create 3 roles

mysql-common  
mysql-master  
mysql-slave

you can make both master & slave depend on common

---

<div class="post-metadata">

**Author:** ![Narcis\_Pillao\_Figuer](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@Narcis\_Pillao\_Figuer](https://forum.ansible.com/u/Narcis_Pillao_Figuer)\
**Post date:** [November 5, 2013, 4:33pm UTC](https://forum.ansible.com/t/different-yml-tasks-files-within-a-role/13825/3 "2013-11-05T16:33:50Z")

</div>

Thanks for your answer Brian.

But there is no way to invoke the yml file if it is in the same role? Something like this? (Obviously the code below is not working)

- hosts: databases  
roles:
- { role: mysql/main.yml, mysql\_root\_password: XXXX, tags: mysql }
- { role: mysql/master.yml, tags: mysql }

I prefer to put this yml file on the same role because I think it is more tidy

Thanks.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [November 5, 2013, 7:20pm UTC](https://forum.ansible.com/t/different-yml-tasks-files-within-a-role/13825/4 "2013-11-05T19:20:52Z")

</div>

‘Include’ can be used no matter where the file is, but it won’t do role magic.

Brian Coca

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 6, 2013, 2:09pm UTC](https://forum.ansible.com/t/different-yml-tasks-files-within-a-role/13825/5 "2013-11-06T14:09:28Z")

</div>

“But there is no way to invoke the yml file if it is in the same role? Something like this? (Obviously the code below is not working)”

There’s no reason why it shouldn’t, role paths can be relative too.

---

<div class="post-metadata">

**Author:** ![Narcis\_Pillao\_Figuer](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@Narcis\_Pillao\_Figuer](https://forum.ansible.com/u/Narcis_Pillao_Figuer)\
**Post date:** [November 7, 2013, 12:01pm UTC](https://forum.ansible.com/t/different-yml-tasks-files-within-a-role/13825/6 "2013-11-07T12:01:58Z")

</div>

Thanks Michael for your answer,

I just double check it again an I can confirm it does not work:

#ls /etc/ansible/roles/mysql/tasks/  
main.yml master.yml

setup.yml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 10, 2013, 9:25pm UTC](https://forum.ansible.com/t/different-yml-tasks-files-within-a-role/13825/7 "2013-11-10T21:25:18Z")

</div>

I’d like to see a github ticket and we can attempt to reproduce it from there.

---

<div class="post-metadata">

**Author:** ![Narcis\_Pillao\_Figuer](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@Narcis\_Pillao\_Figuer](https://forum.ansible.com/u/Narcis_Pillao_Figuer)\
**Post date:** [November 11, 2013, 11:37pm UTC](https://forum.ansible.com/t/different-yml-tasks-files-within-a-role/13825/8 "2013-11-11T23:37:57Z")

</div>

Thanks Michael,

If anyone has the same problem, the issue is tracked here: [https://github.com/ansible/ansible/issues/4876](https://github.com/ansible/ansible/issues/4876)
