Skip to content

Commit

Permalink
created VMWare VM migration
Browse files Browse the repository at this point in the history
  • Loading branch information
adworjan committed Dec 15, 2023
1 parent 6cefa9b commit 5e1499d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .ansible-sign/sha256sum.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ db9832f815d45cb38cc7a54b4712be867ba5300a7b3df4550d9d9c072cd776d9 roles/shadowma
c882455457802d71136ae7beb7bbf00c4f466fe70f978a02c8b3c4f85d0b2e18 roles/shadowman_cores/tasks/vmware_vm_decrease.yml
e5b8e57ae929dce88e87a2c9c5d733f549c2354db9a8dc93a70cddd01128a21a roles/shadowman_cores/tasks/vmware_vm_increase.yml
d5a1c57c596a408447a2052736863e2ce866a6d89b39f73042410188f615930e roles/shadowman_cores/tasks/vmware_vm_restore.yml
187c47956aef9382d96ab512dfa0f524d3a8f7e1da8eee6cdef9f15e28919318 roles/shadowman_esx_vm_migration_memory/tasks/main.yml
cb4153027ba2b948267e16eabc87d026b7d91348014ee9e8df5fc6a123064d02 roles/shadowman_mattermost/defaults/main.yml
04a0267de8ef69af09e732977d37e57f5726aa93679c423835acf350925024bc roles/shadowman_mattermost/tasks/main.yml
63fc480965f44fb833401bcdee3cd66d660e19dd1c933254d0c80f1393350d8d roles/shadowman_mem/defaults/main.yml
Expand Down Expand Up @@ -64,3 +65,4 @@ c9fa212037d2fba2d0ad781c3e902965e195f6e3692a82c551a88399685f4edb systemd_remove
eda7ba55e6c66ed669ba6ce02d367f7cd4df80690d98af28fca810621d10ba75 vm_mem decrease.yml
09f341aa8aace7ccf5ad69de5cf85e711cb29ad1e07208896cf1e45c9f8abe49 vm_mem increase.yml
2b8784ff114a04e4762599c748e7ea45af0dd52f58678b7e5574a64c78efd605 vm_mem restore.yml
f10664e12639b20e92dc051ea06e553335e70f7b5695a7c24c29c15a037d852c vmwarehostinfo.yml
22 changes: 11 additions & 11 deletions .ansible-sign/sha256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MO/xaLtzKcASCodHyqOS2bD+cs5nqPOMKNhXQ+4RGPV1gkTYYcNfOX7W
2OAQkHedVFYVgnAraVwVZe86Jx3WT2/GCTojZWAF8DQntrzuU1e8OgXh0tpYQ8sN
OWXCdIFa7Iy1VipURLsh1c80nPHLDTP2T98f6uyMjeDiYLWKFKN6aCAyDmZ7V+Gd
HA75BSxK
=/hWs
-----END PGP SIGNATURE-----
49 changes: 49 additions & 0 deletions roles/shadowman_esx_vm_migration_memory/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
- name: Gather cluster info from given datacenter

Check failure on line 2 in roles/shadowman_esx_vm_migration_memory/tasks/main.yml

View workflow job for this annotation

GitHub Actions / build

syntax-check[specific]

couldn't resolve module/action 'community.vmware.vmware_cluster_info'. This often indicates a misspelling, missing collection, or incorrect module path.
community.vmware.vmware_cluster_info:
validate_certs: false
datacenter: Shadowman
delegate_to: localhost
register: cluster_info

- name: Get hosts
ansible.builtin.set_fact:
cluster_hosts: "{{ cluster_info | json_query('clusters.*.hosts') | flatten }}"

- name: Get host info
community.vmware.vmware_host_facts:
esxi_hostname: "{{ item.name }}"
validate_certs: false
register: esx_fact
loop: "{{ cluster_hosts }}"

- name: Find ESX host info with most memory
ansible.builtin.set_fact:
most_esx_host_info: "{{ esx_fact.results | sort(attribute='ansible_facts.ansible_memfree_mb') | last }}"

- name: Find ESX host name with most memory
ansible.builtin.set_fact:
most_esx_host_name: "{{ most_esx_host_info.ansible_facts.ansible_hostname }}"

- name: Gather all VMs
community.vmware.vmware_vm_info:
validate_certs: false
vm_type: vm
show_resource_pool: false
show_net: false
show_mac_address: false
show_folder: false
show_datastore: false
show_datacenter: false
show_cluster: false
register: vms

- name: Get name of VM on overloaded esx host
ansible.builtin.set_fact:
vmtomove: "{{ vms.virtual_machines | selectattr('esxi_hostname', 'equalto', overloadedesx) | map(attribute='guest_name') | list | first }}"

- name: Perform vMotion of virtual machine
community.vmware.vmware_vmotion:
validate_certs: false
vm_name: "{{ vmtomove }}"
destination_host: "{{ most_esx_host_name }}"
7 changes: 7 additions & 0 deletions vmwarehostinfo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Migrate VMWare VM due to Memory Issue on ESX Host
hosts: localhost
gather_facts: false

roles:
- shadowman_esx_vm_migration_memory

0 comments on commit 5e1499d

Please sign in to comment.