Ondrej Famera - top logo

(refreshed) Configuring High-Availability clusters in RHEL/Centos with HA-LVM shared storage using Ansible

Refreshing the ansible roles around clusters made me to revisit the nearly 1,5 year old playbook for setting up cluster with HA-LVM. What has changed since then? Playbook is longer :) But does more things in proper way than previous versions did and mostly can run in "dry-run" (--check) mode. Also this time the rgmanager cluster is omitted based on adoption of pacemaker instead of it.

List of ansible roles and their versions used in examples below:

How to use this?

Step 1: Install the roles from ansible galaxy intop directory roles/ using ansible-galaxy install command.

ansible-galaxy install -p roles/ OndrejHome.ha-cluster-pacemaker,v15
ansible-galaxy install -p roles/ OndrejHome.ha-cluster-lvm,v6
ansible-galaxy install -p roles/ OndrejHome.targetcli,v3
ansible-galaxy install -p roles/ OndrejHome.iscsiadm,v2

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

[cluster] vm_name=fastvm-c7.4-51 vm_name=fastvm-c7.4-52 vm_name=fastvm-c7.4-53

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

- hosts: cluster
  remote_user: root
    - { role: 'OndrejHome.iscsiadm' }
    - { role: 'OndrejHome.ha-cluster-pacemaker', cluster_name: 'mycluster' }

- hosts: storage
  remote_user: root
    target_lv_name: 'shared_data'
    target_lv_vg: 'c7vg'
    target_lv_size: '500M'
      - wwn: "iqn.1994-05.com.redhat:shared"
          - path: "/dev/{{target_lv_vg}}/{{target_lv_name}}"
            name: shared_device
            type: block
        initiators: "[ {% for host in groups['cluster'] %} '{{ hostvars[host][\"iscsi_initiator_name\"] }}', {% endfor %} ]"
    - { role: OndrejHome.targetcli }
    - name: create LV for shared data on storage target
      lvol: state=present vg="{{target_lv_vg}}" lv="{{target_lv_name}}" size="{{target_lv_size}}"

- hosts: cluster
  remote_user: root
    target_wwn: "iqn.1994-05.com.redhat:shared"
      - name: 'vg_shared'
        pvs: "/dev/disk/by-path/ip-{{ hostvars[groups['storage'][0]]['ansible_default_ipv4']['address'] }}:3260-iscsi-{{ target_wwn }}-lun-0"
          - name: 'lv_test'
            size: 200
    - { role: 'OndrejHome.iscsiadm', iscsi_target_ip: "{{ hostvars[groups['storage'][0]]['ansible_default_ipv4']['address'] }}" }
    - { role: 'OndrejHome.ha-cluster-lvm', HALVMtype: "tagging" }


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

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

Changes and improvements since last time

Ansible role for HA-LVM was greatly improved to allow proper creating of VGs and LVs for both tagging and clvm variant of HA-LVM. Now it also supports combining both when the role is called 2 times with different HALVMtype, where the result is cluster with both clvm and tagging VGs (note: the clvm should be configured after tagging). iscsiadm module now can detect the initiator name and that can be later used in targetcli module to define ACL for accessing the storage so the initiator names can be left unchanged and just read out of systems. The 'hypervisor_hostname' variable has changed to 'vm_name' that should be both shorter and more intuitive on what it describes. All roles were updated to Ansible 2.4 syntax so there should be no deprecation warnings hopefully.

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. Also please report if something got broken completely and doesn't work anymore.

Last change .