Ansible - Gluster Server Setup
Sun May 10 09:12:19 EDT 2015
Here's a simple playbook (base-gluster.yml) created to install glusterfs-server & glusterfs-client on machines in the hosts (/etc/ansible/hosts) file under group "[clients]"
Each VM is:
1GB ram, 1 cpu, 8GB /dev/vda (root), 8GB /dev/vdb (pvm, for vg01), 1 nic, Ubuntu 14.04, x86_64
Ran on OpenSuse 13.1, under KVM.
==================================================================================
# base-gluster.yml
# by Tom Sandholm
# NOTE: configured for Ubuntu 14.04 distribution...
# NOTE: root public keys shared on all hosts, ssh_config: (Strict is off), sshd_config (PermitRoot is yes)
# SUMMARY: ansible playbook to create glusterfs server on all named hosts in "clients" group
# Tasks:
# 1. install gluster server & client
# 2. create volume group "vg01" from /dev/vdb
# 3. create lvm "global" from vg01
# 4. configure gluster peers
# 5. create gluster volume "global", replica count based on # of [clients] in hosts
# 6. update fstab, noauto on mount due to race issues
# 7. update rc.local to pend on mount of "/usr/global" (via gluster)
#
# NOTE: stole some code from here:
# https://github.com/gc3-uzh-ch/ansible-playbooks/blob/master/roles/gluster/tasks/main.yml
#
# NOTE: Inventory File (/etc/ansible/hosts):
# [clients]
# client01.tsand.org
# client02.tsand.org
# client03.tsand.org
#
---
- hosts: clients
tasks:
- name: install glusterfs-server
apt: name=glusterfs-server update_cache=yes state=installed
- name: install glusterfs-client
apt: name=glusterfs-client update_cache=yes state=installed
- name: create vg01
lvg: vg=vg01 pvs=/dev/vdb
- name: create lvm global
lvol: vg=vg01 lv=global size=2g
- name: create filesystem on global
filesystem: fstype=ext4 dev=/dev/mapper/vg01-global
- name: mount global
mount: name=/share/global src=/dev/mapper/vg01-global fstype=ext4 passno=1 state=mounted
- name: configure gluster peers (on first host)
shell: gluster peer probe {{item}}
with_items: groups.clients
when: inventory_hostname == groups.clients[0]
tags:
- gluster
- name: build brick list
shell: echo {{groups.clients|join(',')}} | sed "s%,%:/share/global/brick %g; s%$%:/share/global/brick%"
register: gluster_bricks
connection: local
sudo: false
tags:
- gluster
- name: build replica count
shell: echo {{groups.clients | length}}
register: replica_count
connection: local
sudo: false
tags:
- gluster
# I really hate doing this. Ran into problems with clients not responding during volume create.
# guess it's load & timing problems...grrr
- name: pause for clients to catch up
pause: seconds=30
- name: create global volume
shell: gluster volume info global || gluster volume create global replica {{ replica_count.stdout }} transport tcp {{ gluster_bricks.stdout }}
when: inventory_hostname == groups.clients[0]
tags:
- gluster
- name: start global volume
shell: 'gluster volume info global | grep "Status: Started" || gluster volume start global'
when: inventory_hostname == groups.clients[0]
tags:
- gluster
- name: create global directory
file: name=/usr/global state=directory
- name: configure global mount
mount: name=/usr/global src=localhost:/global fstype=glusterfs passno=0 opts=noauto,defaults state=present
- name: update rc.local
copy: src=files/rc.local dest=/etc/rc.local owner=root group=root mode=0755
- name: reboot nodes
shell: reboot