Repository: ansible-collections/community.vmware

Issue:
vmware_guest_powerstate - Moved/Copied answers not working with ESXi standalone
<!--- Verify first that your feature was not already discussed on GitHub -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
<!--- Describe the new feature/improvement briefly below -->
Hi.
It looks like answering to the "msg.uuid.altered" question does not work. At least for my standalone ESXi host version 6.7.0.

##### ISSUE TYPE
-  Bug Report

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
vmware_guest_powerstate
##### ADDITIONAL INFORMATION
<!--- Describe how the feature would be used, why it is needed and what it would solve -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- hosts: localhost
  vars_files:
    - vmhost01_vars.yaml
  tasks:
  - name: Automatically answer if a question locked a virtual machine
    block:
      - name: Power on a virtual machine without the answer param
        vmware_guest_powerstate:
          hostname: "{{ esxi_hostname }}"
          username: "{{ esxi_username }}"
          password: "{{ esxi_password }}"
          validate_certs: false
          folder: "/vm"
          name: "{{ vm_name }}"
          state: powered-on
    rescue:
      - name: Power on a virtual machine with the answer param
        vmware_guest_powerstate:
          hostname: "{{ esxi_hostname }}"
          username: "{{ esxi_username }}"
          password: "{{ esxi_password }}"
          validate_certs: false
          folder: "/vm"
          name: "{{ vm_name }}"
          answer:
            - question: "msg.uuid.altered"
              response: "button.uuid.movedTheVM"
          state: powered-on
```

<!--- HINT: You can also paste gist.github.com links for larger files -->

I tried "1", "2", "I moved It", "I Copied It"  as responses, but in any case, it waits for the default answer timeout vui.timeoutUS.question of 4 minutes to continue ( https://kb.vmware.com/s/article/2113542 ).
After 4 minutes the VM gets powered on, but if am logged on to the web client, the dialog stays there waiting for an answer. Clicking Cancel make the dialog go away and VM goes into working state, no more dialogs

The VM log shows that "I copied It" is always the default answer (reply=2), no matter what "response" i declare into the playbook.

```
2022-03-14T13:58:42.287Z| vmx| I125: Msg_Question:
2022-03-14T13:58:42.287Z| vmx| I125: [msg.uuid.altered] This virtual machine might have been moved or copied.
2022-03-14T13:58:42.287Z| vmx| I125+ In order to configure certain management and networking features, VMware ESX needs to know if this virtual machine was moved or copied.
2022-03-14T13:58:42.287Z| vmx| I125+
2022-03-14T13:58:42.287Z| vmx| I125+ If you don't know, answer "I Co_pied It".
2022-03-14T13:58:42.287Z| vmx| I125+
2022-03-14T13:58:42.287Z| vmx| I125: ----------------------------------------
2022-03-14T14:02:42.490Z| vmx| I125: Timing out dialog 18033681
2022-03-14T14:02:42.490Z| vmx| I125: MsgQuestion: msg.uuid.altered reply=2
```


I wonder if I'm doing something wrong.


my ESXI host version information:
Client version: 1.33.7
Client build number: 15803439
ESXi version: 6.7.0
ESXi build number: 17167734



Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
@msilveirabr: Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information.

Here are the items we could not find in your description:
- component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE/bug_report.md

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_missing_data --->
@sky-joker You've implemented this in #821. Do you have an idea why it doesn't work on a standalone ESXi host?

Is it possibly a problem with version 6.7? I think you've tested on vSphere 7 only.
Quick update:
The issue is that I simply copied and pasted the content from https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_guest_powerstate_module.html :
```yaml
- name: Automatically answer if a question locked a virtual machine
  block:
    - name: Power on a virtual machine without the answer param
      vmware_guest_powerstate:
        hostname: "{{ esxi_hostname }}"
        username: "{{ esxi_username }}"
        password: "{{ esxi_password }}"
        validate_certs: false
        folder: "{{ f1 }}"
        name: "{{ vm_name }}"
        state: powered-on
  rescue:
    - name: Power on a virtual machine with the answer param
      vmware_guest_powerstate:
        hostname: "{{ esxi_hostname }}"
        username: "{{ esxi_username }}"
        password: "{{ esxi_password }}"
        validate_certs: false
        folder: "{{ f1 }}"
        name: "{{ vm_name }}"
        answer:
          - question: "msg.uuid.altered"
            response: "button.uuid.copiedTheVM"
        state: powered-on
```

I blindly used the provided example, but **vmware_guest_powerstate** is different from **community.vmware.vmware_guest_powerstate**.

The example should be:

```yaml
- name: Automatically answer if a question locked a virtual machine
  block:
    - name: Power on a virtual machine without the answer param
      community.vmware.vmware_guest_powerstate:
        hostname: "{{ esxi_hostname }}"
        username: "{{ esxi_username }}"
        password: "{{ esxi_password }}"
        validate_certs: false
        folder: "{{ f1 }}"
        name: "{{ vm_name }}"
        state: powered-on
  rescue:
    - name: Power on a virtual machine with the answer param
      community.vmware.vmware_guest_powerstate:
        hostname: "{{ esxi_hostname }}"
        username: "{{ esxi_username }}"
        password: "{{ esxi_password }}"
        validate_certs: false
        folder: "{{ f1 }}"
        name: "{{ vm_name }}"
        answer:
          - question: "msg.uuid.altered"
            response: "button.uuid.copiedTheVM"
        state: powered-on
```
Works fine, both copiedTheVM and movedTheVM show up in vmware.log
Just wondering if the Web UI(when logged onto the ESXi host), the dialog should disappear once ansible is able to answer the question or not... When I'm logged off from the Web UI, the question doesn't show as expected.

So, the only issue here is that the documentation example should be updated.
Should I close this issue and open another, or am I supposed to wait for a dev to manage this ticket? ( Update documentation an close this ticket ?)
Now that's a bit weird. `vmware_guest_powerstate` is just an alias to `community.vmware.vmware_guest_powerstate`, so it should be exactly the same code that's executed. I don't understand the difference.

Anyway, since we prefer to use the fully qualified collection name in examples I'll open a PR to fix the documentation. Don't close the isue, it should be closed automatically when the PR is merged.

Resolving patch:
diff --git a/plugins/modules/vmware_guest_powerstate.py b/plugins/modules/vmware_guest_powerstate.py
--- a/plugins/modules/vmware_guest_powerstate.py
+++ b/plugins/modules/vmware_guest_powerstate.py
@@ -186,7 +186,7 @@
 - name: Automatically answer if a question locked a virtual machine
   block:
     - name: Power on a virtual machine without the answer param
-      vmware_guest_powerstate:
+      community.vmware.vmware_guest_powerstate:
         hostname: "{{ esxi_hostname }}"
         username: "{{ esxi_username }}"
         password: "{{ esxi_password }}"
@@ -196,7 +196,7 @@
         state: powered-on
   rescue:
     - name: Power on a virtual machine with the answer param
-      vmware_guest_powerstate:
+      community.vmware.vmware_guest_powerstate:
         hostname: "{{ esxi_hostname }}"
         username: "{{ esxi_username }}"
         password: "{{ esxi_password }}"


Test patch: