This guide provides a full Ansible playbook to install collectd with distro-aware package handling and service management for Debian 10+, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install collectd
hosts: collectd
become: true
vars:
collectd_plugins:
- cpu
- memory
- disk
- network
- interface
collectd_network_server: "graphite"
collectd_network_port: "25826"
tasks:
- name: Install collectd (Debian/Ubuntu)
apt:
name:
- collectd
- collectd-core
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install collectd (RHEL)
dnf:
name:
- collectd
- collectd-utils
state: present
when: ansible_os_family == "RedHat"
- name: Enable required plugins
lineinfile:
path: /etc/collectd/collectd.conf
regexp: "^#?LoadPlugin {{ item }}"
line: "LoadPlugin {{ item }}"
loop: "{{ collectd_plugins }}"
notify: restart collectd
- name: Configure network plugin
blockinfile:
path: /etc/collectd/collectd.conf
marker: "# {mark} ANSIBLE MANAGED BLOCK - network plugin"
content: |
<Plugin network>
Server "{{ collectd_network_server }}" "{{ collectd_network_port }}"
Forward true
</Plugin>
notify: restart collectd
- name: Enable and start collectd service
service:
name: collectd
state: started
enabled: true
handlers:
- name: restart collectd
service:
name: collectd
state: restarted
25826/udp for sending metrics/etc/collectd/collectd.confAny questions?
Feel free to contact us. Find all contact information on our contact page.