Skip to content
ImagineWorld

Building Out a VMware Deployment

node_idnode-book_learn-ansible_chapter-12-building-out-a-vmware-deployment
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num12
chapter_titleBuilding Out a VMware Deployment
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Chapter 12 — Building Out a VMware Deployment

Section titled “Chapter 12 — Building Out a VMware Deployment”

Now that we know how to launch networking and services in AWS, we will discuss deploying a similar setup in a VMware environment and talk through the core VMware modules.

In this chapter, we will cover the following topics:

  • An introduction to VMware
  • The VMware REST modules

This chapter will discuss various components of the VMware family of products and how you can interact with them using Ansible. While there will be example playbook tasks in this chapter, they may need to be more easily transferable to your installation. Because of this, it’s not recommended that you use any examples in this chapter without first reviewing the complete documentation.

With over 25 years of history, VMware has evolved significantly from its origins as a stealth startup. Boasting a revenue of over $13 billion in August 2023, the Vmware product portfolio, which grew to encompass around 30 products, is best known for its hypervisors, and it is a staple in most enterprises, enabling administrators to deploy virtual machines rapidly across various standard x86-based hardware configurations.

However, recent developments have seen significant changes following Broadcom’s acquisition of Vmware in late 2023.

This acquisition has dramatically simplified Vmware’s product portfolio, something that was influenced by customer and partner feedback, allowing users of all sizes to derive more value from VMware solutions. Two notable offerings include VMware Cloud Foundation and VMware vSphere Foundation, each with advanced add-on offers.

The first of the major changes that Broadcom has implemented is transitioning VMware to a subscription-based model. This aligns with the industry standard for cloud consumption and aims to provide continuous innovation, quicker time to value, and predictable investments for customers by phasing out perpetual licenses and replacing them with subscription or term licenses to enable customer and partner success in digital transformations.

There are concerns from the wider industry about Broadcom’s post-acquisition strategy for VMware. There’s speculation that Broadcom may focus on retaining only the largest and most profitable VMware customers and partners. This strategy could lead to a restructuring of VMware’s portfolio to better align with Broadcom’s business objectives, potentially including asset disposals and an even more streamlined product range.

At the time of writing (early 2024), the impact of these changes on VMware’s existing customer base and partner ecosystem is still unknown, with further details expected to emerge throughout the year as Broadcom continues to implement its strategic long-term plans for VMware.

As already mentioned, there were around 30 products in the VMware range, and Ansible had modules that allowed you to interact with many of them.

However, due to product streamlining, we will just concentrate on the vmware.vmware_rest namespace modules and won’t be looking at any of the community.vmware modules as these will lose all support at some point in 2025.

The difference between the two collections of modules is that, as implied by the name, the vmware.vmware_rest modules use the VMware REST API to manage resources, whereas the ones in community.vmware use a Python library to interact with the various VMware endpoints to perform tasks.

The modules in the vmware.vmware_rest namespace are split into three areas:

  • Appliance: These modules manage your vCenter appliances, which are underlying resources that make up your vCenter deployment
  • Content: The Content Library modules allow you to manage the services for defining and managing the library’s items, subscription, publication, and storage
  • vCenter: These modules allow you to manage the workloads, such as virtual machines, running on top of your vCentre deployment

Let’s start by looking at the VMware REST appliance modules.

At the time of writing, there are over 60 modules; these are split up into their own clearly labeled areas.

To start with, we have the access modules:

  • appliance_access_consolecli: This module allows you to enable or disable the console-based controlled CLI (TTY1).
  • appliance_access_consolecli_info: This module returns the current state of the console-based controlled CLI (TTY1); this will either be enabled or disabled.
  • appliance_access_dcui: With this module, you can configure the state of the Direct Console User Interface (DCUI TTY2); again, you only have two options: enabled or disabled.
  • appliance_access_dcui_info: As you may have already guessed, this module returns either enabled or disabled for the DCUI TTY2 state.
  • appliance_access_shell: Again, there isn’t much to this one in that you just change the enabled state of BASH. With this enabled, you will be able to access a BASH shell within the CLI.
  • appliance_access_shell_info: This module simply returns BASH access; this will either be enabled or disabled.
  • appliance_access_ssh: This module sets the enabled state of the SSH-based controlled CLI.
  • appliance_access_ssh_info: This module returns the enabled state of the SSH-based controlled CLI.

As already mentioned, each of these modules either allows you to set the state of the access system or returns the currently configured state:

- name: "Enable SSH access"
vmware.vmware_rest.appliance_access_ssh:
enabled: true
register: access_ssh_result

Each of the non-info modules has a single value of enabled, which accepts either true or false, as demonstrated earlier.

The next grouping of modules only returns information about the health of your system:

  • appliance_health_applmgmt_info
  • appliance_health_database_info
  • appliance_health_databasestorage_info
  • appliance_health_load_info
  • appliance_health_mem_info
  • appliance_health_softwarepackages_info
  • appliance_health_storage_info
  • appliance_health_swap_info
  • appliance_health_system_info

You would call one of the modules like this:

- name: "Get the system health status"
vmware.vmware_rest.appliance_health_system_info:
register: health_system_result

This would return the current health of whichever of the services you are querying.

Here, we have just two modules:

  • appliance_infraprofile_configs: This module exports the selected profile
  • appliance_infraprofile_configs_info: This module lists all the registered profiles

The only valid state for the appliance_infraprofile_configs module is export:

- name: "Export the ApplianceManagement profile"
vmware.vmware_rest.appliance_infraprofile_configs:
state: "export"
profiles:
- "ApplianceManagement"
register: infraprofile_configs_result

Here’s the output is JSON containing the profile for the selected configuration. In the preceding example, this is ApplianceManagement.

Here, we have three modules:

  • appliance_localaccounts_globalpolicy
  • appliance_localaccounts_globalpolicy_info
  • appliance_localaccounts_info

These modules allow you to set and query the global policy and return information on all or just one of the local accounts.

While there are only two modules here, they can be powerful when you combine them:

  • appliance_monitoring_info: This module returns a list of monitors
  • appliance_monitoring_query: This module allows you to query the monitors

Here’s an example query:

- name: "Query the monitoring backend"
vmware.vmware_rest.appliance_monitoring_query:
start_time: "2024-01-01 09:00:00+00:00"
end_time: "2024-01-01 10:00:00+00:00"
names:
- "mem.total"
interval: "MINUTES5"
function: "AVG"
register: mem_total_result

As you can see, with the preceding task, we are querying the total memory in 5 minutes, which averages between 9 A.M. and 10 A.M. on January 1, 2024.

This is where things start to get a little more complicated; each of the modules has an info equivalent where highlighted:

  • appliance_networking (plus info): This module resets and restarts network configuration on all interfaces. It also renews the DHCP leases for DHCP IP addresses.
  • appliance_networking_dns_domains (plus info): This module is used to manage the DNS search domains.
  • appliance_networking_dns_hostname (plus info): This module configures the fully qualified domain name (FQDN) hostname.
  • appliance_networking_dns_servers (plus info): This module can manage the DNS server configuration.
  • appliance_networking_firewall_inbound (plus info): This module sets an ordered list of firewall rules.
  • appliance_networking_interfaces_info: This module fetches information on a single network interface.
  • appliance_networking_interfaces_ipv4 (plus info): This module manages the IPv4 network configuration for the named network interface.
  • appliance_networking_interfaces_ipv6 (plus info): This module manages the IPv6 network configuration for the named network interface.
  • appliance_networking_noproxy (plus info): This module configures servers for which no proxy configuration should be applied.
  • Appliance_networking_proxy (plus info): This module configures which proxy server to use for the specified protocol.

The following modules affect the time and date settings in some way:

  • appliance_ntp (plus info): This module manages the NTP server configuration
  • appliance_system_time_info: This module gets the system time
  • appliance_system_time_timezone (plus info): This module sets the time zone
  • appliance_timesync module (plus info): This module configures time sync mode

The remaining modules cover appliance configuration and management:

  • appliance_services (plus info): You can use this module to restart a given service
  • appliance_shutdown (plus info): This module allows you to cancel a pending shutdown action
  • appliance_system_globalfips (plus info): Using this module, you can enable or disable Global FIPS mode for the appliance
  • appliance_system_storage (plus info): This module resizes all partitions to 100% of the disk size
  • appliance_system_version_info: This module gets version information
  • appliance_update_info: This module gets the status of an appliance update
  • appliance_vmon_service (plus info): This module lists details of services managed by vmon

This concludes the appliance section. Next, we’ll look at content modules.

There are a small number of modules that allow you to manage and gather information on your content libraries:

  • content_configuration (plus info): This module updates the configuration
  • content_library_item_info: This module returns {@link ItemModel} when provided with an identifier
  • content_locallibrary (plus info): This module creates a new local library
  • content_subscribedlibrary (plus info): This module creates a new subscription

This is where the more interesting things happen. Using these modules, you can launch, configure, and manage the entire life cycle of your virtual machines. Before we look at virtual machines, we’ll take a look at some of the supporting vCenter modules.

These supporting modules allow you to manage things such as data centers, folders, data stores, and resource pools hosted within your vCenter:

  • vcenter_cluster_info: This module retrieves information about the cluster corresponding to {@ param.name cluster_name}
  • vcenter_datacenter (plus info): This module adds a new data center to your vCenter inventory
  • vcenter_datastore_info: This module fetches information about the data store using {@ param.name datastore_name}
  • vcenter_folder_info: This module retrieves information on up to 1,000 folders in vCenter matching {@link FilterSpec} that the user you are connecting as has permission to see
  • vcenter_host (plus info): This module can be used to add a new standalone host to your vCenter
  • vcenter_network_info: This module returns information about the first 1,000 visible networks in vCenter matching {@link FilterSpec}, depending on your permissions
  • vcenter_ovf_libraryitem: This module is used to create an item in the content library from a virtual machine or virtual appliance
  • vcenter_resourcepool (plus info): This module deploys a resource pool
  • vcenter_storage_policies_info: This module fetches information about the storage policies available in vCenter; it returns a maximum of 1,024 results

The final group of modules deals with creating and managing virtual machines and their associated resources. Let’s start by looking at the main module, vcenter_vm.

The vcenter_vm module is used to create virtual machines. For example, a basic task would look like this:

- name: "Create a Virtual Machine"
vmware.vmware_rest.vcenter_vm:
placement:
cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/learnansible_dc/host/learnansible_cluster') }}"
folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/learnansible_dc/vm') }}"
resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/learnansible_dc/host/learnansible_cluster/Resources') }}"
name: "LearnAnsibleVM"
guest_OS: "UBUNTU_64"
hardware_version: "VMX_11"
memory:
hot_add_enabled: true
size_MiB: 4000
register: LearnAnsibleVM_output

As you can see, we are using a few of the different lookup modules to find the cluster, data store, folder, and resource pool IDs – if we had this information, we could provide the IDs directly.

Once the virtual machine has been created, we can use the remaining modules to configure it more or manage its state:

  • vcenter_vm_guest_customization: This module applies guest customization to the virtual machine, such as running a script
  • vcenter_vm_guest_filesystem_directories: Using this module, you can create a directory within the guest host operating system
  • vcenter_vm_guest_identity_info: This module fetches information about the guest host
  • vcenter_vm_guest_localfilesystem_info: This module grabs details of the local filesystems in the guest host operating system
  • vcenter_vm_guest_networking_info: This module fetches details about the network configuration within the guest host operating system
  • vcenter_vm_guest_networking_interfaces_info: This module displays information about the network interfaces in the guest host operating system
  • vcenter_vm_guest_networking_routes_info: This module displays information about the network routes from within the guest host operating system
  • vcenter_vm_guest_operations_info: This module grabs information about the guest host operating system’s status
  • vcenter_vm_guest_power (plus info): This module requests a soft shutdown, standby (suspend), or soft reboot from within the guest host operating system
  • vcenter_vm_hardware: This module is used to update the hardware settings of the requested virtual machine
  • vcenter_vm_hardware_adapter_sata (plus info): This module configures a virtual SATA adapter
  • vcenter_vm_hardware_adapter_scsi (plus info): This module adds a virtual SCSI adapter
  • vcenter_vm_hardware_boot (plus info): This module is used to manage virtual machine boot-related settings
  • vcenter_vm_hardware_boot_device (plus info): This module can set the virtual devices that will be used as the boot drive for your virtual machine
  • vcenter_vm_hardware_cdrom (plus info): This module attaches a virtual CD-ROM to your virtual machine
  • vcenter_vm_hardware_cpu (plus info): This module manages your virtual machine’s CPU settings
  • vcenter_vm_hardware_disk (plus info): This module connects virtual disks to your virtual machine
  • vcenter_vm_hardware_ethernet (plus info): This module connects a virtual Ethernet adapter to your virtual machine
  • vcenter_vm_hardware_floppy (plus info): This module adds a virtual floppy drive to the virtual machine
  • vcenter_vm_hardware_info: This module fetches your virtual machine’s virtual hardware settings information
  • vcenter_vm_hardware_memory (plus info): This module configures the memory settings
  • vcenter_vm_hardware_parallel (plus info): This module adds a virtual parallel port
  • vcenter_vm_hardware_serial (plus info): This module adds a virtual serial port
  • vcenter_vm_info: This module returns information about your virtual machine
  • vcenter_vm_libraryitem_info: This module retrieves information about the library item associated with your virtual machine
  • vcenter_vm_power (plus info): This module issues a boot, hard shutdown, hard reset, or hard suspend on a guest – that is, it presses the power button on the front
  • vcenter_vm_storage_policy (plus info): This module updates the storage policy of your virtual machine’s virtual hard disks
  • vcenter_vm_storage_policy_compliance: This module updates and gathers information on your virtual machine’s storage policy compliance
  • vcenter_vm_tools (plus info): This module is used to manage the configuration of VMware Tools
  • vcenter_vm_tools_installer (plus info): This module attaches the VMware Tools CD installer as a CD-ROM, making it available within the guest host operating system
  • vcenter_vmtemplate_libraryitems (plus info): This module creates and returns information on items in the content library

As you can see, there is comprehensive support for managing your virtual machine resources using the vmware.vmware_rest collection, and what’s better is that the modules are all designed to consume the official REST API, meaning that you can safely mix and match how you manage your resources within VMware, regardless of whether you use the CLI, web interface, or Ansible. Everything is managed via the same REST API.

As you have seen from the very long list of modules, you can do most of the management and configuration tasks you would be doing as a VMware administrator day-to-day using Ansible.

Add to this the modules we looked at in Chapter 8, Ansible Network Modules, for managing network equipment, and modules such as the ones that support hardware such as NetApp storage devices.

By doing this, you can build complex playbooks that span the physical devices, VMware elements, and virtual machines running within your on-premises enterprise-level virtualized infrastructure.

As mentioned at the start of this chapter, at the time of writing, there is a lot of upheaval at VMware. This chapter has been written to show the art of the possible rather than be a practical hands-on guide for managing your VMware resources using Ansible. For more details on the current state of the vmware.vmware_rest collection, go to https://galaxy.ansible.com/ui/repo/published/vmware/vmware_rest/.

In the next chapter, we will look at how to ensure that our playbooks are following best practices by scanning them for common issues and potential security problems.