Ansible Tips For Managing Multiple VMware vCenter Instances
Managing several VMware vCenter instances with Ansible becomes much easier when connection details, credentials and target scope are kept separate. A clean structure reduces duplicated YAML, limits accidental changes and makes automation easier to review when environments span production, development and disaster recovery.
The approach suits Australian IT teams supporting mixed estates across Sydney, Melbourne, Brisbane, Perth or regional sites. Whether the environment runs in a corporate data centre, a colocation facility or a home lab, predictable inventory and careful authentication are more valuable than clever playbook shortcuts.
Build Ansible Inventory Around vCenter Roles
Create inventory groups based on operational purpose rather than placing every vCenter in one flat list. Groups such as production_vcenters, development_vcenters and dr_vcenters allow a playbook to target a service tier without hard-coding individual endpoints.
all:
children:
production_vcenters:
hosts:
vcenter_sydney:
ansible_host: vcsa-syd.example.com
vcenter_melbourne:
ansible_host: vcsa-mel.example.com
development_vcenters:
hosts:
vcenter_brisbane:
ansible_host: vcsa-bne.example.com
Store VMware-specific values in group or host variables. This keeps the playbook reusable while allowing different datacentres, clusters and folders to be selected per vCenter. A naming convention that includes the city or site is especially useful when an operations team is working across Australian time zones.
Keep Credentials Out Of Playbooks
Use Ansible Vault, an external secrets manager or injected CI/CD variables for usernames and passwords. Avoid placing credentials directly in host_vars, even when the repository is private. A committed password can remain in Git history long after the visible line has been removed.
A common pattern is to define vcenter_username and vcenter_password in encrypted variables, then pass them to VMware modules through a shared task file. Environment variables such as VMWARE_USER and VMWARE_PASSWORD can also work for short-lived automation jobs, provided the runner is secured and logs are carefully controlled.
For larger organisations, assign separate service accounts to production and non-production vCenters. Apply least privilege, record ownership and rotate credentials according to internal policy and Australian compliance requirements.
Use Delegation And Explicit Connection Settings
Most community.vmware modules execute through the Ansible controller, which must be able to resolve and reach each vCenter over HTTPS. Set delegate_to: localhost or use a local connection in the play so Ansible does not attempt to run VMware API operations inside a guest virtual machine.
- name: Gather VMware cluster information
community.vmware.vmware_cluster_info:
hostname: "{{ ansible_host }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: true
delegate_to: localhost
register: cluster_info
Use validate_certs: true wherever possible. If internal certificate authorities are not trusted by the controller, install the correct CA chain rather than permanently disabling certificate validation. This is particularly important for automation runners hosted in a separate network or cloud tenancy.
Make Playbooks Safe To Re-Run
Idempotence is essential when managing virtual machines, datastores, folders and clusters. Define the desired state and let the VMware module determine whether a change is required. Avoid shell commands against the vSphere CLI unless no suitable module exists.
Add check_mode, diff support where available and explicit confirmation for destructive actions. A production play should not remove a VM, datastore or folder because a variable was misspelled. Use assertions to verify that the target vCenter, cluster and environment match expectations before applying changes.
For example, require a variable such as change_window_approved before a maintenance task runs. Australian teams often schedule changes outside local business hours, but Sydney daylight saving and Queensland’s lack of daylight saving can create confusing handover times. Store schedules in UTC and display the local conversion in change records.
Scale Across Clusters And Datacentres
When a playbook manages multiple vCenters, loop over inventory hosts rather than duplicating tasks for every site. Host variables can define target_datacenter, target_cluster and target_folder, while the same task file handles each endpoint.
Use serial when changing hosts in a cluster, and add pauses or health checks between operations. This reduces the risk of draining too much capacity at once. It also helps teams supporting busy Melbourne or Sydney environments where a small maintenance error can affect many application owners.
For discovery work, register results per vCenter and label output with the inventory hostname. Clear result naming makes it easier to distinguish a datastore in Perth from one with a similar name in Brisbane. Avoid gathering excessive facts on every run; targeted queries are faster and place less load on the vCenter API.
Handle VMware Module Versions Carefully
Pin the community.vmware collection version in collections/requirements.yml and test upgrades in a non-production vCenter. Module parameters and VMware API behaviour can change, particularly when moving between vSphere releases or upgrading the Ansible execution environment.
A useful project layout might include inventories/production, inventories/lab, group_vars, host_vars, roles and playbooks. The author's background provides useful context for practitioners interested in the infrastructure experience behind this style of VMware automation.
Use linting, syntax checks and Molecule or integration testing where practical. A small lab running on a spare workstation, NUC or nested VMware environment can validate inventory logic before a change reaches a customer platform.
Choose A Practical Execution Model
Running from AWX, Ansible Automation Platform or a controlled CI runner gives teams centralised credentials, job history, approvals and access control. It is usually preferable for recurring operations across many vCenters, while a local workstation remains convenient for development and one-off diagnostics.
For Australian businesses, consider where the automation runner and secrets are hosted. Data sovereignty, customer contracts and Essential Eight-aligned controls may influence whether an organisation uses an Australian cloud region or an on-premises controller. Stable DNS, firewall rules and NTP are just as important as the YAML itself.
| Operating model | Strengths | Best fit | Main caution |
|---|---|---|---|
| Local workstation | Fast development and troubleshooting | Lab or small estate | Weak audit trail |
| Git-based CI runner | Peer review and repeatable execution | Teams with mature repositories | Protect runner secrets |
| AWX or Automation Platform | Approvals, RBAC and job history | Multiple production vCenters | Requires platform administration |
| Scheduled controller | Consistent recurring tasks | Reporting and compliance checks | Monitor failed jobs and stale credentials |
Operational Recommendations
- Group vCenters by environment, site and service ownership.
- Keep credentials encrypted and use separate accounts for production.
- Pin VMware collection versions and test upgrades in a lab.
- Add assertions, check mode and approval gates before changes.
- Record UTC times alongside local Australian maintenance windows.
A disciplined inventory, secure credential model and tested execution path turn Ansible into a dependable control layer for VMware administration. Use the free automation tools alongside a small vSphere lab to refine these patterns, then promote proven playbooks through review and controlled change windows.