Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
smatterchew opened this issue Jan 31, 2023 · 0 comments
Labels

Comments

@smatterchew
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants