Repository: ansible-collections/community.general

Issue:
community.general.proxmox: failed get vm by int parse error if not specify vmid 
### Summary

The following error occurred while trying to delete a VM using communitiy.general.proxmox_kvm.

```
deletion of VM None failed with exception: int() argument must be a string, a bytes-like object or a number, not 'NoneType'.
```

Upon investigation, I found that needed to handle an int parse error in `get_vm` on https://github.com/ansible-collections/community.general/blob/main/plugins/module_utils/proxmox.py#L129.

### Issue Type

Bug Report

### Component Name

proxmox

### Ansible Version

```console (paste below)
$ ansible --version
ansible [core 2.13.0]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.7 (default, Sep 13 2021, 08:18:39) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  jinja version = 3.0.3
  libyaml = True
```


### Community.general Version

```console (paste below)
$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 5.2.0
```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed
# No output
```


### OS / Environment

```console (paste below)
$ cat /etc/redhat-release
Red Hat Enterprise Linux release 8.6 (Ootpa)
```

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: delete kvm instance
  hosts: localhost
  tasks:
    - name: delete kvm instance
      community.general.proxmox_kvm:
        name: "testvm"
        api_host: "{{ ansible_env.PROXMOX_HOST }}"
        api_user: "{{ ansible_env.PROXMOX_USER }}"
        api_token_id: "{{ ansible_env.PROXMOX_API_TOKEN_ID }}"
        api_token_secret: "{{ ansible_env.PROXMOX_API_TOKEN_SECRET }}"
        state: absent
```


### Expected Results

When target vm(testvm) is not found, task result is [ok] and no action.
When target vm(testvm) is found, task result is [changed] and delete vm.


### Actual Results

```console (paste below)

PLAY [delete kvm instance] *****************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [delete kvm instance] *****************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "deletion of VM None failed with exception: int() argument must be a string, a bytes-like object or a number, not 'NoneType'"}

PLAY RECAP *********************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* `plugins/modules/cloud/misc/proxmox`

If these files are incorrect, 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/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @Ajpantuso @Thulium-Drake @joshainglis @karmab @tleguern
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
!component +plugins/module_utils/proxmox.py
Files identified in the description:
* [`plugins/module_utils/proxmox.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/module_utils/proxmox.py)
* `plugins/modules/cloud/misc/proxmox`

If these files are incorrect, 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/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
!component -plugins/modules/cloud/misc/proxmox
Files identified in the description:
* [`plugins/module_utils/proxmox.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/module_utils/proxmox.py)

If these files are incorrect, 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/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->

Resolving patch:
diff --git a/plugins/modules/cloud/misc/proxmox.py b/plugins/modules/cloud/misc/proxmox.py
--- a/plugins/modules/cloud/misc/proxmox.py
+++ b/plugins/modules/cloud/misc/proxmox.py
@@ -743,6 +743,8 @@ def main():
             module.fail_json(msg="restarting of VM %s failed with exception: %s" % (vmid, e))
 
     elif state == 'absent':
+        if not vmid:
+            module.exit_json(changed=False, msg='VM with hostname = %s is already absent' % hostname)
         try:
             vm = proxmox.get_vm(vmid, ignore_missing=True)
             if not vm:
diff --git a/plugins/modules/cloud/misc/proxmox_kvm.py b/plugins/modules/cloud/misc/proxmox_kvm.py
--- a/plugins/modules/cloud/misc/proxmox_kvm.py
+++ b/plugins/modules/cloud/misc/proxmox_kvm.py
@@ -1370,6 +1370,8 @@ def main():
 
     elif state == 'absent':
         status = {}
+        if not vmid:
+            module.exit_json(changed=False, msg='VM with name = %s is already absent' % name)
         try:
             vm = proxmox.get_vm(vmid, ignore_missing=True)
             if not vm:


Test patch: