Enable High Availability (HA) in VMware with Ansible Playbook

In modern IT infrastructure, ensuring that applications and services are always available is crucial. VMware High Availability (HA) is a feature that protects your virtual machines by restarting them on other hosts within a cluster in the event of a host failure. Automating the configuration of HA can save time and effort, especially when managing large environments.

With Ansible, you can automate the configuration of VMware HA settings using the community.vmware.vmware_cluster_ha module. In this article, we’ll guide you through an Ansible playbook that enables and customizes VMware HA in your cluster. Specifically, we will cover enabling HA without admission control, enabling HA with VM monitoring, and configuring HA with admission control that reserves 50% of resources for failover.

 

1. Enable High Availability (HA) Without Admission Control

The first step in configuring HA is enabling it for the desired VMware cluster. Here’s how you can do it using an Ansible task:

 

- name: Enable HA without admission control
  community.vmware.vmware_cluster_ha:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter_name: datacenter
    cluster_name: cluster
    enable: true
  delegate_to: localhost

Breakdown:

  • hostname: The IP address or hostname of the vCenter server where your cluster is located.
  • username and password: The credentials used to authenticate with the vCenter server.
  • datacenter_name: The VMware datacenter name where the cluster resides.
  • cluster_name: The name of the specific VMware cluster where you wish to enable HA.
  • enable: true: This parameter turns on the HA functionality in the specified cluster.
  • delegate_to: localhost: Specifies that the task should be executed from the local machine where the Ansible playbook is running.

This task enables VMware HA without specifying any admission control policies, meaning it will not restrict the amount of resources reserved for HA.

2. Enable High Availability with VM Monitoring

Enabling VM monitoring ensures that if a virtual machine (VM) is not responding, VMware HA can attempt to restart it on another host. Here’s how you can enable HA with VM monitoring using Ansible:

- name: Enable HA and VM monitoring without admission control
  community.vmware.vmware_cluster_ha:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    datacenter_name: DC0
    cluster_name: "{{ cluster_name }}"
    enable: true
    ha_vm_monitoring: vmMonitoringOnly
  delegate_to: localhost

Breakdown:

  • ha_vm_monitoring: vmMonitoringOnly: This configuration enables VM monitoring, but without the additional admission control that reserves resources for failover. The vmMonitoringOnly option means that only VM monitoring will be active.
  • datacenter_name: DC0: Specifies the datacenter name where the cluster is located.
  • cluster_name: Refers to the name of the specific cluster where you wish to enable HA and VM monitoring.

Enabling VM monitoring without admission control can help ensure that VMs are quickly restarted if they fail, but without requiring specific resources to be reserved for HA purposes.

3. Enable High Availability with Admission Control and Resource Reservation

Admission control ensures that sufficient resources are available for HA to work effectively. It controls the amount of resources (CPU and memory) that should be reserved for failover in the event of a host failure. Below is an Ansible task that enables HA with admission control, reserving 50% of resources for failover:

- name: Enable HA with admission control reserving 50% of resources for HA
  community.vmware.vmware_cluster_ha:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter_name: datacenter
    cluster_name: cluster
    enable: true
    reservation_based_admission_control:
      auto_compute_percentages: false
      failover_level: 1
      cpu_failover_resources_percent: 50
      memory_failover_resources_percent: 50
  delegate_to: localhost

Breakdown:

  • reservation_based_admission_control: This section configures the admission control settings, specifically how resources are reserved for HA operations.
    • auto_compute_percentages: false: This ensures that the resource percentages for CPU and memory are manually configured rather than automatically calculated.
    • failover_level: 1: Defines the failover level, meaning the cluster can tolerate a failure of one host without affecting the running virtual machines.
    • cpu_failover_resources_percent: 50: Specifies that 50% of the cluster’s CPU resources are reserved for HA failover.
    • memory_failover_resources_percent: 50: Similarly, 50% of the memory resources are reserved for HA failover.

This configuration ensures that, in case of a host failure, the necessary resources for failover are readily available, which helps prevent service interruptions.

Why Use Ansible for VMware HA Configuration?

Automating VMware HA configuration with Ansible offers several key benefits:

  1. Consistency: By using Ansible playbooks, you can ensure that the same HA settings are applied consistently across multiple clusters and datacenters.
  2. Time-Saving: Manual configuration of HA can be time-consuming, especially in large environments. Ansible playbooks allow for quick and efficient configuration.
  3. Scalability: As your VMware environment grows, you can easily scale HA configurations by modifying and reusing the same playbooks.
  4. Version Control: Ansible playbooks are stored as text files, making them easy to version control and audit, ensuring better collaboration and change tracking.

Example Full Playbook for Enabling HA

Here’s a full example of an Ansible playbook that enables HA, configures VM monitoring, and implements admission control for resource reservation:

---
- name: Configure High Availability (HA) on VMware Cluster
  hosts: localhost
  gather_facts: no
  tasks:
    - name: Enable HA without admission control
      community.vmware.vmware_cluster_ha:
        hostname: '{{ vcenter_hostname }}'
        username: '{{ vcenter_username }}'
        password: '{{ vcenter_password }}'
        datacenter_name: '{{ datacenter_name }}'
        cluster_name: '{{ cluster_name }}'
        enable: true
      delegate_to: localhost

    - name: Enable HA and VM monitoring without admission control
      community.vmware.vmware_cluster_ha:
        hostname: '{{ vcenter_hostname }}'
        username: '{{ vcenter_username }}'
        password: '{{ vcenter_password }}'
        datacenter_name: '{{ datacenter_name }}'
        cluster_name: '{{ cluster_name }}'
        enable: true
        ha_vm_monitoring: vmMonitoringOnly
      delegate_to: localhost

    - name: Enable HA with admission control reserving 50% of resources for HA
      community.vmware.vmware_cluster_ha:
        hostname: '{{ vcenter_hostname }}'
        username: '{{ vcenter_username }}'
        password: '{{ vcenter_password }}'
        datacenter_name: '{{ datacenter_name }}'
        cluster_name: '{{ cluster_name }}'
        enable: true
        reservation_based_admission_control:
          auto_compute_percentages: false
          failover_level: 1
          cpu_failover_resources_percent: 50
          memory_failover_resources_percent: 50
      delegate_to: localhost

This playbook includes all three tasks and will apply the necessary configurations to your VMware cluster.

Ashutosh Dixit

I am currently working as a Senior Technical Support Engineer with VMware Premier Services for Telco. Before this, I worked as a Technical Lead with Microsoft Enterprise Platform Support for Production and Premier Support. I am an expert in High-Availability, Deployments, and VMware Core technology along with Tanzu and Horizon.

Leave a Reply