Deploying Virtual Machines from OVF Templates Using Ansible in VMware vSphere

In VMware environments, automating the deployment of virtual machines (VMs) is essential for improving efficiency, reducing manual errors, and enhancing scalability. One powerful tool that can help automate VM deployment is Ansible. Specifically, the community.vmware.vmware_content_deploy_ovf_template module enables users to deploy VMs directly from OVF templates stored in a content library.

This article will guide you through the process of using an Ansible Playbook to deploy virtual machines (VMs) from OVF templates in VMware vSphere, with detailed examples on configuring the playbook to deploy VMs with standard and specialized storage options, such as eagerZeroedThick provisioning.

What is an OVF Template in VMware?

An OVF (Open Virtualization Format) template is a file format used to package and distribute virtual appliances. OVF templates contain all the necessary files to deploy a virtual machine (including disk and configuration files). The VMware Content Library provides a centralized place to store and manage OVF templates, making it easier to deploy VMs across vSphere environments.

By using OVF templates, you can simplify the process of replicating VMs, ensuring consistent configurations and speeding up the deployment process. Ansible helps automate this deployment, reducing the time and complexity involved.

Why Use Ansible to Deploy VMs from OVF Templates?

Automating VM deployment through Ansible provides several advantages:

  • Efficiency: Speed up the deployment process with automation.
  • Consistency: Ensure consistent VM configurations across environments.
  • Scalability: Deploy multiple VMs simultaneously with minimal effort.
  • Customization: Tailor the deployment process to suit specific needs, such as resource allocation and storage configurations.

Ansible allows users to automate complex workflows and integrate seamlessly with VMware vSphere. This is especially useful in large environments, where deploying VMs manually would be inefficient.

Ansible Playbook for Deploying Virtual Machines from OVF Templates

Here’s an example of an Ansible playbook that uses the community.vmware.vmware_content_deploy_ovf_template module to deploy a VM from an OVF template stored in the VMware Content Library.

Basic Playbook to Deploy VM from OVF Template

- name: Deploy Virtual Machine from OVF template in content library
  community.vmware.vmware_content_deploy_ovf_template:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    ovf_template: rhel_test_template
    datastore: Shared_NFS_Volume
    folder: vm
    datacenter: Sample_DC_1
    name: Sample_VM
    resource_pool: test_rp
  delegate_to: localhost

Explanation of the Ansible Playbook

  1. community.vmware.vmware_content_deploy_ovf_template: This is the Ansible module used to deploy VMs from OVF templates stored in a vSphere content library.

  2. hostname: The hostname or IP address of the vCenter Server that manages your VMware environment.

  3. username: The vCenter Server username with appropriate privileges to deploy VMs.

  4. password: The password associated with the vCenter Server username.

  5. ovf_template: The name of the OVF template that will be used to deploy the VM. In this case, it is rhel_test_template, an example RHEL template stored in the content library.

  6. datastore: Specifies the datastore where the VM will be deployed. Here, Shared_NFS_Volume is selected.

  7. folder: The folder in vSphere where the VM will be placed after deployment. The VM will be placed in the vm folder.

  8. datacenter: The name of the vCenter Datacenter where the deployment will take place.

  9. name: The name of the virtual machine that will be created. In this case, it is Sample_VM.

  10. resource_pool: The name of the resource pool where the VM will be placed. This example uses test_rp.

  11. delegate_to: localhost: This ensures the Ansible task is executed locally from the control machine, as it interacts with the vCenter server remotely.

Advanced Playbook with EagerZeroedThick Storage

To deploy a VM from the OVF template using eagerZeroedThick storage, modify the playbook to include the storage_provisioning option.

- name: Deploy Virtual Machine from OVF template in content library with eagerZeroedThick storage
  community.vmware.vmware_content_deploy_ovf_template:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    ovf_template: rhel_test_template
    datastore: Shared_NFS_Volume
    folder: vm
    datacenter: Sample_DC_1
    name: Sample_VM
    resource_pool: test_rp
    storage_provisioning: eagerZeroedThick
  delegate_to: localhost

Explanation of Key Differences

  • storage_provisioning: eagerZeroedThick: This option specifies the type of disk provisioning to be used for the deployed VM. The eagerZeroedThick provisioning method allocates the full disk space upfront and zeros out the blocks, ensuring that the space is fully allocated and no further changes will be made to the disk blocks.

    • Thick Provisioning: Allocates the full disk space immediately, and eagerZeroedThick also zeroes out all blocks.
    • Thin Provisioning: Allocates disk space dynamically as the VM writes data to the disk, potentially saving storage space initially.

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