This guide provides a full Ansible playbook to deploy Goaccess with Docker Compose on Debian 10+, Ubuntu LTS, and RHEL 9+ compatible hosts.
- name: Deploy Goaccess
hosts: goaccess
become: true
vars:
app_root: /opt/goaccess
app_port: 7890 # Default WebSocket port for real-time updates
goaccess_image_tag: "1.10.1" # Pin to specific version for stability
log_directory: "/var/log/nginx"
config_directory: "/opt/goaccess/config"
tasks:
- name: Install Docker on Debian/Ubuntu
apt:
name:
- docker.io
- docker-compose-plugin
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install Docker on RHEL family
dnf:
name:
- docker
- docker-compose-plugin
state: present
when: ansible_os_family == "RedHat"
- name: Enable and start Docker
service:
name: docker
state: started
enabled: true
- name: Add ansible_user to docker group
user:
name: "{{ ansible_user }}"
groups: docker
append: yes
notify: restart ssh
- name: Create application directories
file:
path: "{{ item }}"
state: directory
mode: "0755"
owner: "{{ ansible_user }}"
loop:
- "{{ app_root }}"
- "{{ config_directory }}"
- name: Write GoAccess configuration file
template:
src: goaccess.conf.j2
dest: "{{ config_directory }}/goaccess.conf"
mode: "0644"
owner: "{{ ansible_user }}"
notify: restart goaccess
- name: Write Docker Compose file
template:
src: docker-compose.yml.j2
dest: "{{ app_root }}/docker-compose.yml"
mode: "0644"
notify: restart goaccess
- name: Start application stack
command: docker compose up -d
args:
chdir: "{{ app_root }}"
register: docker_up_result
- name: Wait for GoAccess to be ready
wait_for:
port: "{{ app_port }}"
delay: 5
timeout: 60
when: docker_up_result.changed
handlers:
- name: restart goaccess
command: docker compose restart
args:
chdir: "{{ app_root }}"
listen: "restart goaccess"
- name: restart ssh
service:
name: ssh
state: restarted
listen: "restart ssh"
Create the following templates in your Ansible roles directory:
# GoAccess Configuration for {{ inventory_hostname }}
# Generated by Ansible
# Log format settings
log-format COMBINED
time-format %H:%M:%S
date-format %d/%b/%Y
# Input/Output settings
log-file /logs/access.log
output /var/www/goaccess/index.html
# Real-time HTML report settings
real-time-html true
ws-url wss://{{ inventory_hostname }}/ws
port {{ app_port }}
# Performance settings
max-items 100
hl-header on
color-scheme 2
# Privacy settings
no-query-string yes
no-ip-validation yes
# GeoIP settings (if enabled)
# geoip-database /usr/share/GeoIP/GeoLite2-City.mmdb
version: '3.8'
services:
goaccess:
image: allinurl/goaccess:{{ goaccess_image_tag }}
restart: unless-stopped
ports:
- "{{ app_port }}:{{ app_port }}"
volumes:
- {{ log_directory }}:/logs:ro
- {{ config_directory }}/goaccess.conf:/etc/goaccess/goaccess.conf:ro
- {{ app_root }}/reports:/var/www/goaccess:rw
command: >
goaccess
--config-file=/etc/goaccess/goaccess.conf
--real-time-html
--port={{ app_port }}
1.10.1) instead of latest for consistency and predictabilitylatest to ensure consistency.Any questions?
Feel free to contact us. Find all contact information on our contact page.