# Ansible best practice

**URL:** <https://forum.ansible.com/t/ansible-best-practice/23604>\
**Category:** Ansible Project\
**Created:** [January 31, 2017, 1:35pm UTC](https://forum.ansible.com/t/ansible-best-practice/23604 "2017-01-31T13:35:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rui\_Goncalves](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@Rui\_Goncalves](https://forum.ansible.com/u/Rui_Goncalves)\
**Post date:** [January 31, 2017, 1:35pm UTC](https://forum.ansible.com/t/ansible-best-practice/23604/1 "2017-01-31T13:35:21Z")

</div>

Hi all,

I have no experience writing ansible roles. At the moment I’m trying to write a few ansible roles, but I’m not sure how to separate responsibilities.

I have two roles.

- prometheus - installs and configures prometheus.
- mongodb - Installs and configures mongodb database.

Prometheus needs to be configured in order to scrap metrics about mongoDB. Basically, it’s necessary to put a file on a directory where the prometheus server is installed, containing information about mongodb location, etc… the question is: Should I configure this on the prometheus role? It seems to me that I’m polluting the prometheus role with things that belong elsewhere. This way, I’m also coupling the prometheus role with a specific use case. It’s recommended to create a separate role to configure mongodb location on prometheus?

What’s the best practice?

Thanks,  
Rui

---

<div class="post-metadata">

**Author:** ![Jinesh\_Choksi](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@Jinesh\_Choksi](https://forum.ansible.com/u/Jinesh_Choksi)\
**Post date:** [January 31, 2017, 2:55pm UTC](https://forum.ansible.com/t/ansible-best-practice/23604/2 "2017-01-31T14:55:38Z")

</div>

Hi Rui,

You can find a role for installing Prometheus here: [https://github.com/kozmagabor/ansible-prometheus](https://github.com/kozmagabor/ansible-prometheus)

Which also has a complementary role to setup the mongodb exporter: [https://github.com/William-Yeh/ansible-mongodb-exporter](https://github.com/William-Yeh/ansible-mongodb-exporter)

I found both of the above via Ansible Galaxy: [https://galaxy.ansible.com/kozmagabor/prometheus/](https://galaxy.ansible.com/kozmagabor/prometheus/)

Ansible Galaxy has several roles available for installing Prometheus.

You could hence avoid creating your own roles and use the above or jump start your own roles based on the above.

To answer your question, it looks cleaner if you split into multiple roles instead of polluting the Prometheus role with something which is not a hard dependency.

Regards,  
Jinesh

---

<div class="post-metadata">

**Author:** ![Rui\_Goncalves](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@Rui\_Goncalves](https://forum.ansible.com/u/Rui_Goncalves)\
**Post date:** [January 31, 2017, 3:29pm UTC](https://forum.ansible.com/t/ansible-best-practice/23604/3 "2017-01-31T15:29:21Z")

</div>

Hi Jinesh.

thank you!

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [January 31, 2017, 5:01pm UTC](https://forum.ansible.com/t/ansible-best-practice/23604/4 "2017-01-31T17:01:28Z")

</div>

Just apply both roles to your mongodb group, and if you want to be explicit  
you'd just set some vars on that group that both roles can use to find  
paths etc.
