Skip to content

Commit

Permalink
update modules from community to vmware.vmware
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemorency committed Aug 6, 2024
1 parent 4344a53 commit 7c4b9b7
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 123 deletions.
2 changes: 1 addition & 1 deletion roles/cluster_settings/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
when: cluster_settings_dpm_enable is defined

- name: Configure DRS Settings
community.vmware.vmware_cluster_drs:
vmware.vmware.cluster_drs:
hostname: "{{ cluster_settings_hostname }}"
username: "{{ cluster_settings_username }}"
password: "{{ cluster_settings_password }}"
Expand Down
13 changes: 3 additions & 10 deletions roles/provision_vcenter/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,19 @@
ansible.builtin.include_tasks: validate_inputs.yml

- name: Check If VCenter Already Exists
community.vmware.vmware_guest_info:
vmware.vmware.guest_info:
hostname: "{{ provision_vcenter_hostname }}"
username: "{{ provision_vcenter_username }}"
password: "{{ provision_vcenter_password }}"
port: "{{ provision_vcenter_port | default(omit) }}"
validate_certs: "{{ provision_vcenter_validate_certs | default(omit) }}"
datacenter: "{{ provision_vcenter_vc_target_datacenter | default('') }}"
datacenter: "{{ provision_vcenter_vc_target_datacenter | default(omit) }}"
name: "{{ provision_vcenter_vm_name }}"
register: _vcenter_lookup
failed_when: false

- name: Fail If There Was An Unexpected Error Looking Up The Guest Info
ansible.builtin.fail:
msg: "{{ _vcenter_lookup.stderr | default(_vcenter_lookup.msg) }}"
when: >-
_vcenter_lookup.instance is not defined and
_vcenter_lookup.msg is not match("Unable to gather information for non-existing VM .*")
- name: Create Instance From ISO
when: _vcenter_lookup.instance is not defined or not _vcenter_lookup.instance
when: not _vcenter_lookup.guests
block:
- name: Gather Required OS Facts
ansible.builtin.setup:
Expand Down
16 changes: 8 additions & 8 deletions roles/provision_virtual_esxi/tasks/deploy_new_esxi_hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
num_cpus: "{{ _esxi.cpus | default(provision_virtual_esxi_cpus) }}"
boot_firmware: "{{ provision_virtual_esxi_boot_firmware }}"
nested_virt: true
when: _result.instance is not defined or not _result.instance
when: not _result.guests
loop: "{{ _esxi_host_check.results }}"
loop_control:
loop_var: _result
Expand All @@ -48,30 +48,30 @@
provision_vm_folder: "{{ provision_virtual_esxi_folder | default(omit) }}"
provision_vm_name: "{{ _result._esxi.name }}"
provision_vm_state: poweredon
when: _result.instance is not defined or not _result.instance
when: not _result.guests
loop: "{{ _esxi_host_check.results }}"
loop_control:
loop_var: _result
label: _result._esxi.name

- name: Wait for New ESXi Deployment
community.vmware.vmware_guest_info:
vmware.vmware.guest_info:
hostname: "{{ provision_virtual_esxi_hostname }}"
username: "{{ provision_virtual_esxi_username }}"
password: "{{ provision_virtual_esxi_password }}"
datacenter: "{{ provision_virtual_esxi_datacenter | default('') }}"
datacenter: "{{ provision_virtual_esxi_datacenter | default(omit) }}"
port: "{{ provision_virtual_esxi_port | default(omit) }}"
validate_certs: "{{ provision_virtual_esxi_validate_certs | default(omit) }}"
name: "{{ _result._esxi.name }}"
when: _result.instance is not defined or not _result.instance
when: not _result.guests
loop: "{{ _esxi_host_check.results }}"
loop_control:
loop_var: _result
label: _result._esxi.name
register: _new_esxi_info
until: >-
_new_esxi_info.instance is defined and
(_new_esxi_info.instance.hw_power_status == 'poweredOff' or
_new_esxi_info.instance.ipv4 or _new_esxi_info.instance.ipv6)
_new_esxi_info.guests and
(_new_esxi_info.guests[0].hw_power_status == 'poweredOff' or
_new_esxi_info.guests[0].ipv4 or _new_esxi_info.guests[0].ipv6)
retries: 30
delay: 15
8 changes: 3 additions & 5 deletions roles/provision_virtual_esxi/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
fail_msg: Variable must be set when using this role.

- name: Check For Missing Hosts
community.vmware.vmware_guest_info:
vmware.vmware.guest_info:
hostname: "{{ provision_virtual_esxi_hostname }}"
username: "{{ provision_virtual_esxi_username }}"
password: "{{ provision_virtual_esxi_password }}"
port: "{{ provision_virtual_esxi_port | default(omit) }}"
datacenter: "{{ provision_virtual_esxi_datacenter | default('') }}"
datacenter: "{{ provision_virtual_esxi_datacenter | default(omit) }}"
validate_certs: "{{ provision_virtual_esxi_validate_certs | default(omit) }}"
name: "{{ _esxi.name }}"
failed_when: false
Expand All @@ -27,9 +27,7 @@
label: _esxi.name

- name: Include New ESXi Hosts Tasks
when: >-
(_esxi_host_check.results | selectattr('instance', 'undefined') is any) or
(_esxi_host_check.results | selectattr('instance', 'defined') | map(attribute='instance') is not all)
when: (_esxi_host_check.results | map(attribute='guests') is not all)
block:
- name: Check VM Mandatory Variables Are Defined
ansible.builtin.assert:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Get VM Info
community.vmware.vmware_guest_info:
vmware.vmware.guest_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
Expand Down Expand Up @@ -52,9 +52,9 @@
vcenter_validate_certs: false
source:
type: VirtualMachine
id: "{{ vm_info.instance.moid }}"
id: "{{ vm_info.guests[0].moid }}"
target:
library_id: "{{ content_library_id }}"
create_spec:
name: "{{ ovf_library_item_name }}"
state: present
state: present
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Get VM Info
community.vmware.vmware_guest_info:
vmware.vmware.guest_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
Expand All @@ -12,15 +12,15 @@
- name: Check Properties Of VM {{ item }}
ansible.builtin.assert:
that:
- guest_info.instance.hw_cluster == deploy_ovf_cluster_name
- guest_info.instance.hw_folder == deploy_ovf_folder
- guest_info.instance.hw_name == item
- guest_info.instance.hw_datastores == [deploy_ovf_datastore]
- guest_info.instance.hw_memtotal_mb == test_vm_hardware.memory_mb
- guest_info.instance.hw_processor_count == test_vm_hardware.num_cpus
- guest_info.guests[0].hw_cluster == deploy_ovf_cluster_name
- guest_info.guests[0].hw_folder == deploy_ovf_folder
- guest_info.guests[0].hw_name == item
- guest_info.guests[0].hw_datastores == [deploy_ovf_datastore]
- guest_info.guests[0].hw_memtotal_mb == test_vm_hardware.memory_mb
- guest_info.guests[0].hw_processor_count == test_vm_hardware.num_cpus

- name: Check Power Status Of VM Deployed From Local OVF File
ansible.builtin.assert:
that:
- guest_info.instance.hw_power_status == vm_power_status
when: item == vm_name_local_ovf
- guest_info.guests[0].hw_power_status == vm_power_status
when: item == vm_name_local_ovf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
name: cloud.vmware_ops.provision_virtual_esxi

- name: Wait until ESXi VM is powered off after OS installation
community.vmware.vmware_guest_info:
vmware.vmware.guest_info:
hostname: "{{ provision_virtual_esxi_hostname }}"
username: "{{ provision_virtual_esxi_username }}"
password: "{{ provision_virtual_esxi_password }}"
Expand All @@ -40,7 +40,7 @@
validate_certs: "{{ provision_virtual_esxi_validate_certs }}"
name: "{{ provision_virtual_esxi_vms[0].name }}"
register: _esxi_power_status
until: _esxi_power_status.instance.hw_power_status == 'poweredOff'
until: _esxi_power_status.guests[0].hw_power_status == 'poweredOff'
retries: 30
delay: 20

Expand All @@ -51,7 +51,7 @@
provision_vm_state: "poweredon"

- name: Wait until ESXi VM has an IP address
community.vmware.vmware_guest_info:
vmware.vmware.guest_info:
hostname: "{{ provision_virtual_esxi_hostname }}"
username: "{{ provision_virtual_esxi_username }}"
password: "{{ provision_virtual_esxi_password }}"
Expand All @@ -60,13 +60,13 @@
validate_certs: "{{ provision_virtual_esxi_validate_certs }}"
name: "{{ provision_virtual_esxi_vms[0].name }}"
register: _esxi_host_check
until: _esxi_host_check.instance.ipv4 is defined and _esxi_host_check.instance.ipv4 is not none
until: _esxi_host_check.guests[0].ipv4 is defined and _esxi_host_check.guests[0].ipv4 is not none
retries: 30
delay: 10

- name: Check if ESXi is up
wait_for:
host: "{{ _esxi_host_check.instance.ipv4 }}"
host: "{{ _esxi_host_check.guests[0].ipv4 }}"
port: 22
delay: 10
timeout: 300
Expand All @@ -77,18 +77,18 @@
name: cloud.vmware_ops.vcenter_host_connection
vars:
vcenter_host_connection_state: present
vcenter_host_connection_esxi_hostname: "{{ _esxi_host_check.instance.ipv4 }}"
vcenter_host_connection_esxi_hostname: "{{ _esxi_host_check.guests[0].ipv4 }}"

- name: Enable Maintenance Mode
ansible.builtin.import_role:
name: cloud.vmware_ops.esxi_maintenance_mode
vars:
esxi_maintenance_mode_esxi_hostname: "{{ _esxi_host_check.instance.ipv4 }}"
esxi_maintenance_mode_esxi_hostname: "{{ _esxi_host_check.guests[0].ipv4 }}"
esxi_maintenance_mode_enable: True

- name: Gather ESXI host facts after enabling maintenance mode
community.vmware.vmware_host_facts:
hostname: "{{ _esxi_host_check.instance.ipv4 }}"
hostname: "{{ _esxi_host_check.guests[0].ipv4 }}"
username: "{{ vcenter_host_connection_esxi_username }}"
password: "{{ vcenter_host_connection_esxi_password }}"
validate_certs: "{{ esxi_maintenance_mode_validate_certs }}"
Expand All @@ -105,12 +105,12 @@
ansible.builtin.import_role:
name: cloud.vmware_ops.esxi_maintenance_mode
vars:
esxi_maintenance_mode_esxi_hostname: "{{ _esxi_host_check.instance.ipv4 }}"
esxi_maintenance_mode_esxi_hostname: "{{ _esxi_host_check.guests[0].ipv4 }}"
esxi_maintenance_mode_enable: False

- name: Gather ESXI host facts after disabling maintenance mode
community.vmware.vmware_host_facts:
hostname: "{{ _esxi_host_check.instance.ipv4 }}"
hostname: "{{ _esxi_host_check.guests[0].ipv4 }}"
username: "{{ vcenter_host_connection_esxi_username }}"
password: "{{ vcenter_host_connection_esxi_password }}"
validate_certs: "{{ esxi_maintenance_mode_validate_certs }}"
Expand All @@ -132,7 +132,7 @@
datacenter: "{{ vcenter_host_connection_datacenter }}"
cluster: "{{ vcenter_host_connection_cluster }}"
validate_certs: "{{ vcenter_host_connection_validate_certs }}"
esxi_hostname: "{{ _esxi_host_check.instance.ipv4 | default('') }}"
esxi_hostname: "{{ _esxi_host_check.guests[0].ipv4 | default('') }}"
esxi_username: "{{ vcenter_host_connection_esxi_username }}"
esxi_password: "{{ vcenter_host_connection_esxi_password }}"
state: absent
Expand All @@ -151,4 +151,4 @@
- name: Run task for removing resource pool
ansible.builtin.include_tasks: add_or_remove_resource_pool.yml
vars:
state: absent
state: absent
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
provision_vm_force: true

- name: Check if ESXi VM is down
command: ping -c 1 -W 5 {{ esxi_host.instance.ipv4 }}
command: ping -c 1 -W 5 {{ esxi_host.guests[0].ipv4 }}
register: ping_check_result
ignore_errors: true

Expand All @@ -38,7 +38,7 @@
ping_not_available: "{{ ping_check_result.rc != 0 }}"

- name: Verify VM absence in vCenter
community.vmware.vmware_guest_info:
vmware.vmware.guest_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
Expand Down
Loading

0 comments on commit 7c4b9b7

Please sign in to comment.