vm_disk – Manage VM’s disks
Use this module to add, delete or set disks to the VM. The module can also remove all disks from a VM, attach and/or detach ISO image to the VM by ISO’s name, detach ISO image from the VM by disk’s disk slot, or update the existing disks (disk size etc.).
New in version 0.0.1.
Examples
- name: Set exact disk
scale_computing.hypercore.vm_disk:
vm_name: demo-vm
force_reboot: true
shutdown_timeout: "{{ '5minutes' | community.general.to_time_unit('seconds') }}"
items:
- disk_slot: 0
type: virtio_disk
size: "{{ '10.1 GB' | human_to_bytes }}"
state: set
- name: Remove all disks
scale_computing.hypercore.vm_disk:
vm_name: demo-vm
items: []
state: set
force: true
- name: Remove one disk
scale_computing.hypercore.vm_disk:
vm_name: demo-vm
items:
- disk_slot: 0
type: virtio_disk
state: absent
- name: Example add/update one disk.
scale_computing.hypercore.vm_disk:
vm_name: demo-vm
items:
- disk_slot: 0
type: virtio_disk
size: "{{ '10.1 GB' | human_to_bytes }}"
state: present
- name: Attach existing ISO image to existing VM
scale_computing.hypercore.vm_disk:
vm_name: demo-vm
items:
- name: CentOS-Stream-9-latest-x86_64-dvd1.iso
disk_slot: 0
type: ide_cdrom
state: present
- name: Detach ISO image from cdrom disk on slot 0
scale_computing.hypercore.vm_disk:
vm_name: demo-vm
items:
- name: CentOS-Stream-9-latest-x86_64-dvd1.iso
disk_slot: 0
type: ide_cdrom
state: absent
- name: Detach ISO image from existing VM, find CD-ROM by slot number and type
scale_computing.hypercore.vm_disk:
vm_name: demo-vm
items:
- disk_slot: 0
type: ide_cdrom
state: absent
- name: Update existing disk - resize, change type etc
scale_computing.hypercore.vm_disk:
vm_name: demo-vm
items:
- disk_slot: 0
type: ide_disk
type_new: virtio_disk
size: "{{ '11.1 GB' | human_to_bytes }}"
cache_mode: writeback
state: present
- name: Resize disk
scale_computing.hypercore.vm_disk:
vm_name: demo-vm
items:
- disk_slot: 0
type: virtio_disk
size: "{{ '20 GB' | human_to_bytes }}"
state: present
Notes
Note
check_mode is not supported.
Parameters
- cluster_instance (optional)
Scale Computing HyperCore instance information.
type: dict- host (required)
The HyperCore instance URL.
If not set, the value of the
SC_URLenvironment variable will be used.For example “https://10.1.2.3:443”.
type: str- password (required)
Password used for authentication.
If not set, the value of the
SC_PASSWORDenvironment variable will be used.type: str- timeout (optional)
Timeout in seconds for the connection with the Scale Computing HyperCore API instance.
If not set, the value of the
SC_TIMEOUTenvironment variable will be used.type: float- username (required)
Username used for authentication.
If not set, the value of the
SC_USERNAMEenvironment variable will be used.type: str
- force (optional)
A safeguard to prevent unintentional removal of all disks.
To remove all disks, items should be set to items=[] and state should be state=set (see example below).
In addition, the force=true must be provided.
type: bool- force_reboot (optional)
Can VM be forced to power off and on.
Only used when modifications to the VM require it to be powered off and VM does not respond to a shutdown request within shutdown_timeout limit.
Before this is utilized, a shutdown request is sent.
type: bool- items (optional)
The disk items we want to change.
type: list- cache_mode (optional)
The cache mode the VM will use.
type: strchoices: none, writeback, writethrough- disable_snapshotting (optional)
Disables the ability to snapshot the drive.
type: bool- disk_slot (required)
Virtual slot the drive will occupy.
type: int- iso_name (optional)
The name of ISO image we want to attach/detach from existing VM.
In case of attaching ISO image (see example below), name is required.
In case of detaching ISO image (see example below), name is optional. If not specified, ISO image present on the
ide_cdromdisk will get removed.type: str- size (optional)
Logical size of the device in bytes. Can be used for resizing or creating the disk.
In case you’re creating a disk, size needs to be specified.
type: int- tiering_priority_factor (optional)
SSD tiering priority factor for block placement.
Check the tiering documentation for best practices when modifying this.
tiering_priority_factor won’t be relevant on cluster that only has a single tier - ie. only spinning disk or all flash.
type: int- type (required)
The bus type the VirDomainBlockDevice will use.
If type=ide_cdrom, it’s assumed you want to attach ISO image to cdrom disk. In that case, field name is required.
type: strchoices: ide_cdrom, virtio_disk, ide_disk, scsi_disk, ide_floppy, nvram- type_new (optional)
Only relevant if we want to update the disk parameters.
The type we want to assign the disk with.
type: str
- shutdown_timeout (optional)
How long does ansible controller wait for VMs response to a shutdown request.
In seconds.
type: floatdefault: 300- state (required)
The desired state of the disks specified by items.
With state=present (or state=absent), the disks in items are added to VM, or removed from VM. Individual disk is resized if needed.
With state=set, the VM is reconfigured to have exactly such disks as specified by items.
type: strchoices: present, absent, set- vm_name (required)
Virtual machine name.
Used to identify selected virtual machine by name.
type: str
Return Values
- record
The modified record from the HyperCore API endpoint
/rest/v1/VirDomainBlockDevice.sample:
cache_mode: NONE disable_snapshotting: false disk_slot: 0 mount_points: [] name: jc1-disk-0 read_only: false size: 81001000100 tiering_priority_factor: 8 type: VIRTIO_DISK uuid: 056ea04b-069c-4a22-84d5-5489b100029f vm_uuid: 1596dab1-6f90-494c-9607-b14221830433