Resizing the Vmware VMDK Through Ansible script

217 views
Skip to first unread message

JC JC

unread,
Jun 9, 2020, 2:18:15 AM6/9/20
to Ansible Project

Hi Team,

 

I'm looking for ansible script to resize my Existing Virtual machine Primary Hard disk (VMDK).

 

Cheers

Shiva Shankar S

Abhijeet Kasurde

unread,
Jun 9, 2020, 7:06:24 AM6/9/20
to ansible...@googlegroups.com
Hi Shiva,

You can do like this -

---
- hosts: localhost
  gather_facts: false
  vars_files:
    - vcenter_vars.yml
  tasks:
  - name: Resize to 10GB from 4GB
    vmware_guest_disk:
      validate_certs: False
      hostname: '{{ vcenter_hostname }}'
      username: '{{ vcenter_username }}'
      password: '{{ vcenter_password }}'
      datacenter: Asia-Datacenter1
      name: vm_8046
      disk:
        - datastore: "ds_171_2"
          scsi_controller: 0
          scsi_type: 'paravirtual'
          size_gb: 10
          state: present
          unit_number: 0

TASK [Resize to 10GB from 4GB] **********************************************************************
task path: /Volumes/data/src/playbooks/vmware/vmware_guest_disk_resize.yml:7
redirecting (type: modules) ansible.builtin.vmware_guest_disk to community.vmware.vmware_guest_disk
changed: [localhost] => {"changed": true, "disk_changes": {"0": "Disk size increased."}, "disk_data": {"0": {"backing_datastore": "ds_171_2", "backing_disk_mode": "persistent", "backing_eagerlyscrub": false, "backing_filename": "[ds_171_2] vm_8046/vm_8046.vmdk", "backing_thinprovisioned": false, "backing_writethrough": false, "capacity_in_bytes": 10737418240, "capacity_in_kb": 10485760, "controller_key": 1000, "iolimit_limit": -1, "iolimit_shares_level": "normal", "iolimit_shares_limit": 1000, "key": 2000, "label": "Hard disk 1", "shares_level": "normal", "shares_limit": 1000, "summary": "10,485,760 KB", "unit_number": 0}}}


If you have multiple disks, you need to gather information about all disk and pass it to vmware_guest_disk before making any changes.

You can take the help of this playbook https://github.com/Akasurde/ansible-reproducers/blob/master/55999/i55999.yml. (This playbook adds a new disk to configuration, but can be modified to resize disk as well)

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/43fc8a33-8db1-46bb-8875-ca8333c3caeeo%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

JC JC

unread,
Jun 10, 2020, 1:14:10 AM6/10/20
to ansible...@googlegroups.com

HI Abhijeet,

 

Thanks a lot for your script, I need one more help that after VM HDD space increased on VM level, we need to perform some task on OS level to see the additional disk space, do you have any ansible script or any help from you.


Cheers
Shiva Shankar S

Abhijeet Kasurde

unread,
Jun 10, 2020, 1:18:38 AM6/10/20
to ansible...@googlegroups.com
What kind of tasks do you need to run on the OS level? You can either use `vmware_vm_shell` to run command or add that VM as ansible host using `add_host` and run command in subsequent plays.



--
Thanks,
Abhijeet Kasurde

Tony Wong

unread,
Jun 10, 2020, 8:15:19 AM6/10/20
to ansible...@googlegroups.com
Interested in this too.  I got a windows VM with only C drive. I want to resize from 60GB to 70GB

how do i set up the playbook

Message has been deleted

Duy Huynh Đỗ

unread,
Feb 14, 2023, 2:30:28 AM2/14/23
to Ansible Project
Dear Abhijeet Kasurde,

Thanks a lot for your script, the disk upgrade on vcenter was successful but windows os can't boot again (blue screen) after disk is expanded by script

I am using ansible 2.10.8, vcenter 8
Please help me !

winboot error.jpg

Vào lúc 19:15:19 UTC+7 ngày Thứ Tư, 10 tháng 6, 2020, Tony Wong đã viết:

Thanh Nguyen Duc

unread,
Feb 14, 2023, 3:50:55 AM2/14/23
to ansible...@googlegroups.com
I don’t think vmware support to resize the disk by decrease the volume size directly. Likely the disk shrink already removed some file systems from OS and cause the OS not able to boot up. 

Thanks and Best Regards,

Thanh.

On 14 Feb 2023, at 15:30, Duy Huynh Đỗ <duyhu...@gmail.com> wrote:


Dear Abhijeet Kasurde,

Thanks a lot for your script, the disk upgrade on vcenter was successful but windows os can't boot again (blue screen) after disk is expanded by script

I am using ansible 2.10.8, vcenter 8
Please help me !

Reply all
Reply to author
Forward
0 new messages