How to Add a Disk to a VMware VM Using Ansible Playbook
By Luca Berton · Published 2024-01-01 · Category: troubleshooting
Learn how to add a disk to a VMware VM using an Ansible playbook. This guide includes the YAML configuration, variables, and execution steps for easy automation.
Introduction • Module: community.vmware.vmware_guest_disk • Purpose: Manage disks related to virtual machines in a given vCenter infrastructure
The Ansible module vmware_guest_disk is part of the community-supported collection of modules for interacting with VMware. It manages disks associated with virtual machines within a specified vCenter infrastructure.
Parameters Overview • Connection Details: • hostname (string) • username (string) • password (string) • datacenter (string) • validate_certs (boolean) • SCSI Controller Details: • scsi_controller (string) • unit_number (string) • scsi_type (string) • Disk Size: • size_kb / size_mb / size_gb / size_tb (string) • Disk Mode: • disk_mode (string: persistent, independent_persistent, independent_nonpersistent)
To add a disk to a VMware vSphere Virtual Machine using the vmware_guest_disk module, you must first establish a connection to VMware vSphere or VMware vCenter. This is done using parameters such as hostname, username, password, datacenter, and validate_certs.
Once connected, you can specify the desired disk configuration to add a new disk to the virtual machine. The required parameters are datacenter and unit_number. The datacenter parameter identifies the datacenter to which the virtual machine belongs.
The disk must be connected to a SCSI controller inside the virtual machine, so parameters like scsi_controller, unit_number, and scsi_type are essential. You can specify the disk size using units like KB, MB, GB, or TB.
One crucial parameter is disk_mode, which defaults to persistent. Other options include independent_persistent and independent_nonpersistent.
For more detailed information, refer to the official community.vmware.vmware_guest_disk documentation.
Playbook Example
I'll Playbooknstrate how to add a 1GB additional disk to a Virtual Machine named "myvm" using an Ansible Playbook. The disk will be added to SCSI controller number 1, unit number 1.
Playbook • vm_add_disk.yml
Variables: vars.yml
Inventory
Execution
Run the following command to execute the playbook:
Expected output:
before execution
!vmware_guest_disk before execution
after execution
!vmware_guest_disk after execution
Conclusion
This Playbooknstrates a successful disk addition to the specified virtual machine using Ansible. Now you know how to Add disk to VMware vSphere Virtual Machine with Ansible.
Related Articles • Ansible Become Guide • Ansible Inventory Guide
Category: troubleshooting
Watch the video: How to Add a Disk to a VMware VM Using Ansible Playbook — Video Tutorial