# vmotion condition

**URL:** <https://forum.ansible.com/t/vmotion-condition/32816>\
**Category:** Ansible Project\
**Created:** [April 29, 2020, 6:56pm UTC](https://forum.ansible.com/t/vmotion-condition/32816 "2020-04-29T18:56:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mani](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mani](https://forum.ansible.com/u/Mani)\
**Post date:** [April 29, 2020, 6:56pm UTC](https://forum.ansible.com/t/vmotion-condition/32816/1 "2020-04-29T18:56:53Z")

</div>

I am trying to perform vmotion of multiple VMs between 2 ESXi hosts using the vmare\_vmotion module. We need to set a cap for memory utilization of the destination host to \<= 70% and the storage utilization to \<= 90%.

Required result: VMs have to be migrated until the memory and storage utilization has reached. The loop should stop VM migration once the memory & storage threshold has reached.

- name: Perform storage vMotion and host vMotion of virtual machine  
vmware\_vmotion:  
hostname: “{{ running\_host }}”  
username: “{{ esxi\_user }}”  
password: “{{ esxi\_pass }}”  
validate\_certs: no  
vm\_name: “{{ item.guest\_name }}”  
destination\_host: “{{ destination\_host }}”  
destination\_datastore: “{{ item.name }}”  
delegate\_to: localhost  
with\_nested:
- “{{vm\_info.virtual\_machines}}”
- “{{ansible\_datastore}}”

Any inputs is highly appreciated.

---

<div class="post-metadata">

**Author:** ![Mani](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mani](https://forum.ansible.com/u/Mani)\
**Post date:** [May 7, 2020, 9:49am UTC](https://forum.ansible.com/t/vmotion-condition/32816/2 "2020-05-07T09:49:53Z")

</div>

Real-time memory and datastore calculation using the pre-defined module for VMware.Please provide if this is achievable in Ansible or not.

Thanks,  
Mani

---

<div class="post-metadata">

**Author:** ![Mani](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mani](https://forum.ansible.com/u/Mani)\
**Post date:** [May 15, 2020, 11:03pm UTC](https://forum.ansible.com/t/vmotion-condition/32816/3 "2020-05-15T23:03:49Z")

</div>

Can we invoke any script to capture the memory and datastore utilization?

---

<div class="post-metadata">

**Author:** ![David\_Foley](https://avatars.discourse-cdn.com/v4/letter/d/9e8a1a/32.png) [@David\_Foley](https://forum.ansible.com/u/David_Foley)\
**Post date:** [May 19, 2020, 1:08pm UTC](https://forum.ansible.com/t/vmotion-condition/32816/4 "2020-05-19T13:08:54Z")

</div>

Hi Mani,

Your best bet would be to use PowerCLI, [https://communities.vmware.com/thread/539904?start=15&tstart=0](https://communities.vmware.com/thread/539904?start=15&tstart=0)

---

<div class="post-metadata">

**Author:** ![Mani](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mani](https://forum.ansible.com/u/Mani)\
**Post date:** [May 21, 2020, 12:45am UTC](https://forum.ansible.com/t/vmotion-condition/32816/5 "2020-05-21T00:45:57Z")

</div>

Hi David,

Thank you for the info.
