This guide provides a full Ansible playbook to install Graphite with distro-aware package handling and service management for Debian 10+, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install Graphite
hosts: graphite
become: true
vars:
graphite_web_admin_user: "admin"
graphite_web_admin_password: "changeme"
tasks:
- name: Install Graphite packages (Debian/Ubuntu)
apt:
name:
- graphite-web
- graphite-carbon
- python3-django
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install Graphite packages (RHEL)
dnf:
name:
- graphite-web
- graphite-carbon
state: present
enablerepo: epel
when: ansible_os_family == "RedHat"
- name: Configure Carbon
lineinfile:
path: /etc/carbon/carbon.conf
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
loop:
- { regexp: '^ENABLE_RUNNER =', line: 'ENABLE_RUNNER = True' }
- { regexp: '^USER =', line: 'USER = graphite' }
notify: restart carbon-cache
- name: Initialize Graphite database (Debian/Ubuntu)
command: graphite-manage migrate
args:
creates: /var/lib/graphite/graphite.db
when: ansible_os_family == "Debian"
- name: Create Graphite admin user
shell: |
graphite-manage shell << EOF
from django.contrib.auth.models import User
if not User.objects.filter(username='{{ graphite_web_admin_user }}').exists():
User.objects.create_superuser('{{ graphite_web_admin_user }}', 'admin@example.com', '{{ graphite_web_admin_password }}')
EOF
args:
creates: /var/lib/graphite/.admin-created
when: ansible_os_family == "Debian"
- name: Enable and start Carbon service
service:
name: carbon-cache
state: started
enabled: true
- name: Enable and start Apache (Debian/Ubuntu)
service:
name: apache2
state: started
enabled: true
when: ansible_os_family == "Debian"
handlers:
- name: restart carbon-cache
service:
name: carbon-cache
state: restarted
80/tcp or 8080/tcp - Web interface2003/tcp - Carbon plaintext protocol2004/tcp - Carbon pickle protocolcarbon-cache for metric storage, web server for UI/etc/carbon/carbon.conf and /etc/graphite/local_settings.pyAny questions?
Feel free to contact us. Find all contact information on our contact page.