Ondrej Famera - top logo

Configuring High-Availability clusters in RHEL/CentOS with shared storage and HA-LVM using ansible

The title explains quite well what the following ansible playbook is cabable of. Despite being still a basic solution focusing at just bringing up the quite basic configuration you get an HA cluster with proper HA-LVM configuration for any combination of rgmanager/pacemaker clvm/tragging HA-LVM type which can save time and headaches. Links for roles used are below:

  • OndrejHome.ha-cluster-rgmanager / OndrejHome.ha-cluster-pacemaker
  • OndrejHome.ha-cluster-lvm
  • OndrejHome.targetcli
  • OndrejHome.ha-cluster-iscsiadm

How to use this?

Step 1: Install the roles from ansible galaxy as root using ansible-galaxy install command.

ansible-galaxy install OndrejHome.ha-cluster-pacemaker
ansible-galaxy install OndrejHome.ha-cluster-rgmanager
ansible-galaxy install OndrejHome.ha-cluster-lvm
ansible-galaxy install OndrejHome.targetcli
ansible-galaxy install OndrejHome.iscsiadm

Step 2: Create the inventory file containing host on which you want to create a cluster and host taht will be an iSCSI storage server. For example a 3-node cluster inventory file example is below. Note that you have to use hypervisor_name variables if the ansible role should setup a fencing devices using fence_xvm for you.

[storage]
192.168.34.50
[cluster]
192.168.34.51 hypervisor_hostname=fastvm-c6.8-51
192.168.34.52 hypervisor_hostname=fastvm-c6.8-52
192.168.34.53 hypervisor_hostname=fastvm-c6.8-53
ansible_hosts.txt

Step 3: Use following playbook and customize the variables to your liking. In below example the resulting cluster will use the CLVM HA-LVM storage on pacemaker cluster.


---
## iSCSI storage server for cluster nodes
- hosts: storage
  remote_user: root
  pre_tasks:
  ## prepare storage on iSCSI server (optional if you already have a partition/LV that you want to export)
    - name: create LV for shared data on storage target
      lvol: state=present vg="{{target_lv_vg}}" lv="{{target_lv_name}}" size="{{target_lv_size}}"
  roles:
    - { role: OndrejHome.targetcli }
  vars:
    target_lv_name: 'shared_data'       # (optional) (required for pre_tasks)
    target_lv_vg: 'c7vg'                # (optional) (required for pre_tasks)
    target_lv_size: '2g'                # (optional) (required for pre_tasks)
    target_wwn: 'iqn.1994-05.com.redhat:shared' # iSCSI server WWN which cluster nodes will use
    client_wwn: 'iqn.1994-05.com.redhat:client' # WWN of cluster nodes - all nodes will have same WWN
    iscsi_shared_device: "/dev/{{target_lv_vg}}/{{target_lv_name}}" # path to device exported by iSCSI
    iscsi_targets:
      - target1:
        wwn: "{{ target_wwn }}"
        disks:
          - disk1:
            path: "{{ iscsi_shared_device }}"
            name: shared_device
            type: block
        initiators:
          - client1:
            wwn: "{{ client_wwn }}"

## Install cluster, iSCSI initiator and configure HA-LVM
- hosts: cluster
  remote_user: root
  vars:
    client_wwn: 'iqn.1994-05.com.redhat:client' # (required if using iSCSI as storage) iSCSI server WWN which cluster nodes will use
    target_wwn: 'iqn.1994-05.com.redhat:shared' # (required if using iSCSI as storage) WWN of cluster nodes - all nodes will have same WWN
    iscsi_server_ip: "{{ hostvars[groups['storage'][0]]['ansible_eth0']['ipv4']['address'] }}" # Take IP address of first machine in 'storage' group which should contain the iSCSI server IP
    name_of_cluster: 'mycluster'        # name of cluster
    cluster_type: 'pacemaker'           # (required) type of cluster - 'rgmanager' or 'pacemaker'
    lvm_type: 'clvm'                    # (required) HA-LVM type - 'clvm' or 'tagging'
  roles:
    - { role: "OndrejHome.iscsiadm", iscsi_target_ip: "{{ iscsi_server_ip }}", iscsi_target_wwn: "{{ target_wwn }}", iscsi_initiator_wwn: "{{ client_wwn }}" }
    - { role: "OndrejHome.ha-cluster-{{ cluster_type }}", cluster_name: "{{ name_of_cluster }}" }
    - { role: "OndrejHome.ha-cluster-lvm", HALVMtype: "{{ lvm_type }}", cluster_vg_name: "cluster_vg", shared_drive: '/dev/disk/by-path/ip-{{ iscsi_server_ip }}:3260-iscsi-{{ target_wwn }}-lun-0' }

ansible_playbook.yml

Step 4: Run the ansible and wait for cluster to get created.

$ ansible-playbook -i ansible_hosts.txt ansible_playbook.yml

Notes and limitations

Most of the code is a proof-of-concept quality and may brake if used on existing environment. Limitations from underlying roles applies. The playbook was tested mostly on CentOS but should work also on RHEL in most cases.

Feel free to create issues on github if you encounter any issues in the above roles or if you would like some special feature be included in them.

Last change .