ansible-collections / vmware.vmware_rest

Ansible Collection for VMWare (REST modules)
https://ansible-collections.github.io/vmware.vmware_rest/
GNU General Public License v3.0
132 stars 65 forks source link

guest_OS not updated on VM #427

Open mgollo opened 1 year ago

mgollo commented 1 year ago
SUMMARY

When running vmware.vmware_rest.vcenter_vm on an existing, powered-off VM with a new value for guest_OS, the guest operating system of the machine is not updated.

ISSUE TYPE
COMPONENT NAME

vmware.vmware_rest.vcenter_vm

ANSIBLE VERSION
ansible [core 2.15.4]
  config file = None
  configured module search path = ['/Users/martin.gollowitzer/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/martin.gollowitzer/code/venv/ansible-vcenter-test/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/martin.gollowitzer/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/martin.gollowitzer/code/venv/ansible-vcenter-test/bin/ansible
  python version = 3.11.4 (main, Jun 20 2023, 16:59:59) [Clang 14.0.3 (clang-1403.0.22.14.1)] (/Users/martin.gollowitzer/code/venv/ansible-vcenter-test/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
Collection         Version
------------------ -------
vmware.vmware_rest 2.3.1  

# /Users/martin.gollowitzer/code/venv/ansible-vcenter-test/lib/python3.11/site-packages/ansible_collections
Collection         Version
------------------ -------
vmware.vmware_rest 2.3.1  
CONFIGURATION
CONFIG_FILE() = None
EDITOR(env: EDITOR) = vim
PAGER(env: PAGER) = less
OS / ENVIRONMENT

Playbook was run on macOS against VMware vCenter version7.0.3

STEPS TO REPRODUCE

A VM that was installed with RHEL 8, but a guest_OS setting of RHEL_7_64 when RHEL_8_64 was not yet available due to an older version of vSphere. The machine was powered off and should have been updated using the following task within the playbook:

---
- name: "lookup MoID of {{ item }}"
  set_fact: 
    moid: "{{ lookup('vmware.vmware_rest.vm_moid', '/DC/vm/folder/' + item ) }}"
- name: "Get VM info for {{ item }}"
  vmware.vmware_rest.vcenter_vm_info:
    vcenter_validate_certs: false
    vm: "{{ moid }}"
  register: vm_info
- name: "Shut down {{ item }} via OS after successful upgrade"
  vmware.vmware_rest.vcenter_vm_guest_power:
    vcenter_validate_certs: false
    state: shutdown
    vm: "{{ moid }}"
- name: "Wait until {{ item }}  is off"
  vmware.vmware_rest.vcenter_vm_info:
    vm: '{{ moid }}'
  register: vm_post_off_info
  until:
  - vm_post_off_info is not failed
  - vm_post_off_info.value.power_state == "POWERED_OFF"
  retries: 60
  delay: 10
- name: "Change operating system of {{ item }} to RHEL 8 if necessary"
  vmware.vmware_rest.vcenter_vm:
    vcenter_validate_certs: false
    guest_OS: "RHEL_8_64"
    vm: "{{ moid }}"
    state: "present"
  register: os_change
  when:
    - vm_info.value.guest_OS == "RHEL_7_64"
EXPECTED RESULTS

The guest_OS should have the new value.

ACTUAL RESULTS

The tasked reported no changes. The VM settings remained unchanged.

TASK [debug os upgrade result] *****************************************************************************************************************************************************
ok: [localhost] => {
    "msg": {
        "changed": false,
        "failed": false,
        "id": "vm-XXXXXX",
...
            "guest_OS": "RHEL_7_64",
...
}
machacekondra commented 8 months ago

Indeed, it's not possible to update guest_OS via VMware REST API. So we are blocked by the API.