Introduction

GlusterFS is a scalable distributed file system that aggregates storage from multiple servers into a single namespace. Ansible automates cluster setup — install GlusterFS, form trusted pools, create replicated or distributed volumes, mount on clients, configure geo-replication, and manage snapshots.

Deploy GlusterFS Cluster

---
- name: Deploy GlusterFS cluster
  hosts: gluster_nodes
  become: true
  vars:
    gluster_brick_dir: /data/gluster/brick1
    gluster_volume_name: gv0
    gluster_replicas: 3
  tasks:
    - name: Install GlusterFS server
      ansible.builtin.package:
        name: glusterfs-server
        state: present

    - name: Start GlusterFS
      ansible.builtin.service:
        name: glusterd
        state: started
        enabled: true

    - name: Allow GlusterFS through firewall
      ansible.posix.firewalld:
        service: glusterfs
        permanent: true
        state: enabled
        immediate: true

    - name: Create brick directory
      ansible.builtin.file:
        path: "{{ gluster_brick_dir }}"
        state: directory
        mode: '0755'

    - name: Peer probe (form trusted pool)
      gluster.gluster.gluster_peer:
        state: present
        nodes: "{{ groups['gluster_nodes'] }}"
      run_once: true

    - name: Create replicated volume
      gluster.gluster.gluster_volume:
        state: present
        name: "{{ gluster_volume_name }}"
        bricks: "{{ gluster_brick_dir }}/{{ gluster_volume_name }}"
        replicas: "{{ gluster_replicas }}"
        cluster: "{{ groups['gluster_nodes'] }}"
        options:
          performance.cache-size: 256MB
          performance.write-behind-window-size: 1MB
          server.allow-insecure: "on"
          nfs.disable: "on"
      run_once: true

    - name: Start volume
      gluster.gluster.gluster_volume:
        state: started
        name: "{{ gluster_volume_name }}"
      run_once: true

Volume Types

Distributed Volume (striped across nodes)

- name: Create distributed volume
  gluster.gluster.gluster_volume:
    state: present
    name: dist-vol
    bricks: /data/gluster/dist
    cluster: "{{ groups['gluster_nodes'] }}"
  run_once: true

Distributed-Replicated Volume

- name: Create distributed-replicated volume (6 nodes, replica 3)
  gluster.gluster.gluster_volume:
    state: present
    name: dist-rep-vol
    bricks: /data/gluster/dr
    replicas: 3
    cluster: "{{ groups['gluster_nodes'] }}"
  run_once: true

Arbiter Volume (saves space)

- name: Create arbiter volume
  gluster.gluster.gluster_volume:
    state: present
    name: arbiter-vol
    bricks: /data/gluster/arb
    replicas: 3
    arbiters: 1
    cluster: "{{ groups['gluster_nodes'] }}"
  run_once: true

Mount on Clients

---
- name: Mount GlusterFS on clients
  hosts: gluster_clients
  become: true
  vars:
    gluster_mount_point: /mnt/gluster
    gluster_volume_name: gv0
  tasks:
    - name: Install GlusterFS client
      ansible.builtin.package:
        name: glusterfs-client
        state: present

    - name: Create mount point
      ansible.builtin.file:
        path: "{{ gluster_mount_point }}"
        state: directory
        mode: '0755'

    - name: Mount GlusterFS volume
      ansible.posix.mount:
        path: "{{ gluster_mount_point }}"
        src: "{{ groups['gluster_nodes'][0] }}:/{{ gluster_volume_name }}"
        fstype: glusterfs
        opts: "defaults,_netdev,backup-volfile-servers={{ groups['gluster_nodes'][1:] | join(':') }}"
        state: mounted

Performance Tuning

- name: Tune GlusterFS volume
  ansible.builtin.command: >
    gluster volume set {{ gluster_volume_name }} {{ item.key }} {{ item.value }}
  loop:
    - { key: performance.cache-size, value: "512MB" }
    - { key: performance.io-thread-count, value: "32" }
    - { key: performance.write-behind-window-size, value: "4MB" }
    - { key: performance.readdir-ahead, value: "on" }
    - { key: performance.stat-prefetch, value: "on" }
    - { key: client.event-threads, value: "4" }
    - { key: server.event-threads, value: "4" }
  run_once: true
  changed_when: true

Snapshots

- name: Create volume snapshot
  ansible.builtin.command: >
    gluster snapshot create snap-{{ ansible_date_time.date }}
    {{ gluster_volume_name }} no-timestamp
  run_once: true
  changed_when: true

- name: List snapshots
  ansible.builtin.command: gluster snapshot list
  register: snap_list
  changed_when: false
  run_once: true

- name: Delete old snapshots (keep last 7)
  ansible.builtin.shell: |
    gluster snapshot list | head -n -7 | while read snap; do
      gluster snapshot delete "$snap" --mode=script
    done
  run_once: true
  changed_when: true

Geo-Replication

- name: Set up geo-replication
  block:
    - name: Create geo-rep session
      ansible.builtin.command: >
        gluster volume geo-replication {{ gluster_volume_name }}
        {{ geo_rep_remote_user }}@{{ geo_rep_remote_host }}::{{ geo_rep_remote_volume }}
        create push-pem
      run_once: true

    - name: Start geo-replication
      ansible.builtin.command: >
        gluster volume geo-replication {{ gluster_volume_name }}
        {{ geo_rep_remote_user }}@{{ geo_rep_remote_host }}::{{ geo_rep_remote_volume }}
        start
      run_once: true
      changed_when: true

Health Check

- name: Check volume status
  ansible.builtin.command: gluster volume status {{ gluster_volume_name }}
  register: vol_status
  changed_when: false
  run_once: true

- name: Check peer status
  ansible.builtin.command: gluster peer status
  register: peer_status
  changed_when: false

- name: Check for split-brain
  ansible.builtin.command: >
    gluster volume heal {{ gluster_volume_name }} info split-brain
  register: split_brain
  changed_when: false
  run_once: true

- name: Alert on split-brain
  ansible.builtin.debug:
    msg: "⚠️ Split-brain detected in {{ gluster_volume_name }}"
  when: "'Number of entries: 0' not in split_brain.stdout"
  run_once: true

Troubleshooting

Heal Volume

- name: Trigger volume heal
  ansible.builtin.command: gluster volume heal {{ gluster_volume_name }}
  run_once: true
  changed_when: true

- name: Check heal status
  ansible.builtin.command: gluster volume heal {{ gluster_volume_name }} info
  register: heal_info
  changed_when: false
  run_once: true

Conclusion

GlusterFS provides distributed file storage without a single point of failure — Ansible automates the entire cluster lifecycle using the gluster.gluster collection. Form trusted pools, create replicated volumes for HA, distributed volumes for capacity, tune performance, manage snapshots, and set up geo-replication for DR. All storage configuration lives in your playbooks alongside the applications that consume it.