vmware.vmware_rest icon indicating copy to clipboard operation
vmware.vmware_rest copied to clipboard

vmware.vmware_rest.vcenter_vm_guest_power returns `changed: false` when shutting down a VM

Open smatterchew opened this issue 1 year ago • 0 comments

Ansible version:

ansible [core 2.11.12] 
  config file = /home/user/.ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/ansible/os9_prov_vmw_20230117/lib64/python3.6/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/ansible/os9_prov_vmw_20230117/bin/ansible
  python version = 3.6.8 (default, Aug 13 2020, 07:46:32) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
  jinja version = 3.0.3
  libyaml = True

Collection version:

vmware.vmware_rest    2.2.0

The implementation:

- name: "The VM is powered off"
  delegate_to: localhost
  vmware.vmware_rest.vcenter_vm_guest_power:
    vcenter_hostname: "{{ svrreq_vm.vcenter }}"
    vcenter_username: "{{ survey_username }}"
    vcenter_password: "{{ survey_password }}"
    vm: "{{ deployed_vm.vm_deploy_info.vm_id }}"
    state: shutdown
  register: vm_shutdown

The result when the VM was running before the call:

ok: [localhost -> localhost] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "session_timeout": null,
            "state": "shutdown",
            "vcenter_hostname": "vcenter",
            "vcenter_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "vcenter_rest_log_file": null,
            "vcenter_username": "user",
            "vcenter_validate_certs": true,
            "vm": "vm-17058"
        }
    },
    "value": {}
}

The result when the VM was powered off before the call:

ok: [localhost -> localhost] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "session_timeout": null,
            "state": "shutdown",
            "vcenter_hostname": "vcenter",
            "vcenter_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "vcenter_rest_log_file": null,
            "vcenter_username": "user",
            "vcenter_validate_certs": true,
            "vm": "vm-17058"
        }
    },
    "value": {
        "error_type": "ALREADY_IN_DESIRED_STATE",
        "messages": [
            {
                "args": [
                    "vm-17058:d3013894-63b8-4a83-af62-9e89cf6a79a1"
                ],
                "default_message": "Virtual machine with identifier 'vm-17058:d3013894-63b8-4a83-af62-9e89cf6a79a1' is already powered off.",
                "id": "com.vmware.api.vcenter.vm.guest.power.already_powered_off"
            },
            {
                "args": [],
                "default_message": "The attempted operation cannot be performed in the current state (Powered off).",
                "id": "vmsg.InvalidPowerState.summary"
            }
        ]
    }
}

Expected results:

changed: true is returned by the module when there is a power state change.

Actual results:

changed: false is returned by the module when there is a power state change. To actually detect a power state change I would need to call vmware.vmware_rest.vcenter_vm_guest_power_info first and compare the power state to the result of this call to detect a change. This would get messy when changing the power state of more than one VM at a time.

smatterchew avatar Jan 31 '23 16:01 smatterchew