From d40cfaa9564f7eb3f7b667970bcc9db900389226 Mon Sep 17 00:00:00 2001 From: Pablo Moreno Date: Fri, 11 Nov 2016 04:02:58 +0000 Subject: [PATCH] adds glusterfs role for ansible. --- roles/glusterfs/README.md | 44 +++++++++++++++++++++++ roles/glusterfs/defaults/main.yml | 11 ++++++ roles/glusterfs/meta/main.yml | 30 ++++++++++++++++ roles/glusterfs/tasks/main.yml | 49 ++++++++++++++++++++++++++ roles/glusterfs/tasks/setup-Debian.yml | 26 ++++++++++++++ roles/glusterfs/tasks/setup-RedHat.yml | 11 ++++++ roles/glusterfs/tests/test.yml | 5 +++ roles/glusterfs/vars/Debian.yml | 2 ++ roles/glusterfs/vars/RedHat.yml | 2 ++ 9 files changed, 180 insertions(+) create mode 100644 roles/glusterfs/README.md create mode 100644 roles/glusterfs/defaults/main.yml create mode 100644 roles/glusterfs/meta/main.yml create mode 100644 roles/glusterfs/tasks/main.yml create mode 100644 roles/glusterfs/tasks/setup-Debian.yml create mode 100644 roles/glusterfs/tasks/setup-RedHat.yml create mode 100644 roles/glusterfs/tests/test.yml create mode 100644 roles/glusterfs/vars/Debian.yml create mode 100644 roles/glusterfs/vars/RedHat.yml diff --git a/roles/glusterfs/README.md b/roles/glusterfs/README.md new file mode 100644 index 000000000..0b4d794e5 --- /dev/null +++ b/roles/glusterfs/README.md @@ -0,0 +1,44 @@ +# Ansible Role: GlusterFS + +[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-glusterfs.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-glusterfs) + +Installs and configures GlusterFS on Linux. + +## Requirements + +For GlusterFS to connect between servers, TCP ports `24007`, `24008`, and `24009`/`49152`+ (that port, plus an additional incremented port for each additional server in the cluster; the latter if GlusterFS is version 3.4+), and TCP/UDP port `111` must be open. You can open these using whatever firewall you wish (this can easily be configured using the `geerlingguy.firewall` role). + +This role performs basic installation and setup of Gluster, but it does not configure or mount bricks (volumes), since that step is easier to do in a series of plays in your own playbook. Ansible 1.9+ includes the [`gluster_volume`](https://docs.ansible.com/gluster_volume_module.html) module to ease the management of Gluster volumes. + +## Role Variables + +Available variables are listed below, along with default values (see `defaults/main.yml`): + + glusterfs_default_release: "" + +You can specify a `default_release` for apt on Debian/Ubuntu by overriding this variable. This is helpful if you need a different package or version for the main GlusterFS packages (e.g. GlusterFS 3.5.x instead of 3.2.x with the `wheezy-backports` default release on Debian Wheezy). + + glusterfs_ppa_use: yes + glusterfs_ppa_version: "3.5" + +For Ubuntu, specify whether to use the official Gluster PPA, and which version of the PPA to use. See Gluster's [Getting Started Guide](http://www.gluster.org/community/documentation/index.php/Getting_started_install) for more info. + +## Dependencies + +None. + +## Example Playbook + + - hosts: server + roles: + - geerlingguy.glusterfs + +For a real-world use example, read through [Simple GlusterFS Setup with Ansible](http://www.jeffgeerling.com/blog/simple-glusterfs-setup-ansible), a blog post by this role's author, which is included in Chapter 8 of [Ansible for DevOps](https://www.ansiblefordevops.com/). + +## License + +MIT / BSD + +## Author Information + +This role was created in 2015 by [Jeff Geerling](http://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). diff --git a/roles/glusterfs/defaults/main.yml b/roles/glusterfs/defaults/main.yml new file mode 100644 index 000000000..5580ed271 --- /dev/null +++ b/roles/glusterfs/defaults/main.yml @@ -0,0 +1,11 @@ +--- +# For Ubuntu. +glusterfs_default_release: "" +glusterfs_ppa_use: yes +glusterfs_ppa_version: "3.5" + +# Gluster configuration. +gluster_mount_dir: /mnt/gluster +gluster_volume_node_mount_dir: /mnt/xfs-drive-gluster +gluster_brick_dir: "{{ gluster_volume_node_mount_dir }}/brick" +gluster_brick_name: gluster diff --git a/roles/glusterfs/meta/main.yml b/roles/glusterfs/meta/main.yml new file mode 100644 index 000000000..c53f17159 --- /dev/null +++ b/roles/glusterfs/meta/main.yml @@ -0,0 +1,30 @@ +--- +dependencies: [] + +galaxy_info: + author: geerlingguy + description: GlusterFS installation for Linux. + company: "Midwestern Mac, LLC" + license: "license (BSD, MIT)" + min_ansible_version: 2.0 + platforms: + - name: EL + versions: + - 6 + - 7 + - name: Ubuntu + versions: + - precise + - trusty + - xenial + - name: Debian + versions: + - wheezy + - jessie + galaxy_tags: + - system + - networking + - cloud + - clustering + - files + - sharing diff --git a/roles/glusterfs/tasks/main.yml b/roles/glusterfs/tasks/main.yml new file mode 100644 index 000000000..c7e526618 --- /dev/null +++ b/roles/glusterfs/tasks/main.yml @@ -0,0 +1,49 @@ +--- +# Include variables and define needed variables. +- name: Include OS-specific variables. + include_vars: "{{ ansible_os_family }}.yml" + +# Instal xfs package +- name: install xfs Debian + apt: name=xfsprogs state=present + when: ansible_os_family == "Debian" + +- name: install xfs RedHat + yum: name=xfsprogs state=present + when: ansible_os_family == "RedHat" + +# Format external volumes in xfs +- name: Format volumes in xfs + filesystem: fstype=xfs dev=/dev/vdb + +# Mount external volumes +- name: mounting new xfs filesystem + mount: "name={{ gluster_volume_node_mount_dir }} src=/dev/vdb fstype=xfs state=mounted" + +# Setup/install tasks. +- include: setup-RedHat.yml + when: ansible_os_family == 'RedHat' + +- include: setup-Debian.yml + when: ansible_os_family == 'Debian' + +- name: Ensure GlusterFS is started and enabled at boot. + service: "name={{ glusterfs_daemon }} state=started enabled=yes" + +- name: Ensure Gluster brick and mount directories exist. + file: "path={{ item }} state=directory mode=0775" + with_items: + - "{{ gluster_brick_dir }}" + - "{{ gluster_mount_dir }}" + +- name: Configure Gluster volume. + gluster_volume: + state: present + name: "{{ gluster_brick_name }}" + brick: "{{ gluster_brick_dir }}" + replicas: "{{ groups['gfs-cluster'] | length }}" + cluster: "{{ groups['gfs-cluster'] | map('extract', hostvars, ['ansible_eth0', 'ipv4', 'address']) | join(',') }}" + host: "{{ inventory_hostname }}" + force: yes + run_once: true + diff --git a/roles/glusterfs/tasks/setup-Debian.yml b/roles/glusterfs/tasks/setup-Debian.yml new file mode 100644 index 000000000..e156e4b3f --- /dev/null +++ b/roles/glusterfs/tasks/setup-Debian.yml @@ -0,0 +1,26 @@ +--- +- name: Add PPA for GlusterFS. + apt_repository: + repo: 'ppa:gluster/glusterfs-{{ glusterfs_ppa_version }}' + state: present + update_cache: yes + register: glusterfs_ppa_added + when: glusterfs_ppa_use + +- name: Ensure GlusterFS will reinstall if the PPA was just added. + apt: + name: "{{ item }}" + state: absent + with_items: + - glusterfs-server + - glusterfs-client + when: glusterfs_ppa_added.changed + +- name: Ensure GlusterFS is installed. + apt: + name: "{{ item }}" + state: installed + default_release: "{{ glusterfs_default_release }}" + with_items: + - glusterfs-server + - glusterfs-client diff --git a/roles/glusterfs/tasks/setup-RedHat.yml b/roles/glusterfs/tasks/setup-RedHat.yml new file mode 100644 index 000000000..257c0106c --- /dev/null +++ b/roles/glusterfs/tasks/setup-RedHat.yml @@ -0,0 +1,11 @@ +--- +- name: Install Prerequisites + yum: name={{ item }} state=present + with_items: + - "centos-release-gluster{{ glusterfs_default_release }}" + +- name: Install Packages + yum: name={{ item }} state=present + with_items: + - glusterfs-server + - glusterfs-client diff --git a/roles/glusterfs/tests/test.yml b/roles/glusterfs/tests/test.yml new file mode 100644 index 000000000..3646ff420 --- /dev/null +++ b/roles/glusterfs/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: all + + roles: + - role_under_test diff --git a/roles/glusterfs/vars/Debian.yml b/roles/glusterfs/vars/Debian.yml new file mode 100644 index 000000000..13c595f74 --- /dev/null +++ b/roles/glusterfs/vars/Debian.yml @@ -0,0 +1,2 @@ +--- +glusterfs_daemon: glusterfs-server diff --git a/roles/glusterfs/vars/RedHat.yml b/roles/glusterfs/vars/RedHat.yml new file mode 100644 index 000000000..e931068ae --- /dev/null +++ b/roles/glusterfs/vars/RedHat.yml @@ -0,0 +1,2 @@ +--- +glusterfs_daemon: glusterd