# developing a role for collectd

**URL:** <https://forum.ansible.com/t/developing-a-role-for-collectd/14585>\
**Category:** Ansible Project\
**Tags:** galaxy-ng\
**Created:** [February 17, 2014, 11:27pm UTC](https://forum.ansible.com/t/developing-a-role-for-collectd/14585 "2014-02-17T23:27:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Martin](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@James\_Martin](https://forum.ansible.com/u/James_Martin)\
**Post date:** [February 17, 2014, 11:27pm UTC](https://forum.ansible.com/t/developing-a-role-for-collectd/14585/1 "2014-02-17T23:27:12Z")

</div>

tl;dr - What's the best way (if there is one) to develop a general  
purpose re-usable role for something that's seems infinitely  
configurable ?

I'm working on developing a role for collectd, hopefully something  
that is useful enough to be published to ansible-galaxy.

collectd is a tool used to gather system/app metrics from many  
endpoints, and forward them on to somewhere else or write them to  
disk.

For each kind of metric in collectd exists its own specific  
configuration. Luckily the product has a /etc/collectd.d/ directory,  
so you can have a disk.conf, apache.conf, memory.conf, myapp.conf,  
etc.

I can think of two different ways to model collect into roles --

Option 1 -- Roles and Dependent Roles

Have one common role call collectd-common -- this would install the  
package, setup the service, and set up a very basic configuration  
file.

All other configuration is done through roles that depend on  
collectd-common. These dependent roles would likely not make it on  
ansible-galaxy since they could be too site-specific. For example:  
collectd-myapp, collectd-mysystem, etc.

I think if there was a sub-role for every different plugin (20+ in  
total), then things are going to get very role sprawly.

Option 2 -- One Big Role

Have one collectd role that installs collectd but is aware of all the  
various collectd plugins that are available -- it has templates for  
each one --, and you simply tell it which plugins you'd like to  
activate and which variables are going to be used to configure those  
templates.

This would require quite a big chunk of complex vars, and lots of  
template logic.

Thanks!

- James

---

<div class="post-metadata">

**Author:** ![Marc\_Trudel](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Marc\_Trudel](https://forum.ansible.com/u/Marc_Trudel)\
**Post date:** [February 18, 2014, 6:18am UTC](https://forum.ansible.com/t/developing-a-role-for-collectd/14585/2 "2014-02-18T06:18:00Z")

</div>

What I generally do:

- Have a conf.d folder where other roles can drop config which they need
- Have these said roles drop configs of their own in that said folder

Then make sure that roles are run in proper order. We have a couple of things here which we run like this (firewall, collectd, nginx, etc), and it has been working pretty well so far.
