Repository: ansible-collections/community.general

Issue:
Proxmox_kvm - setting state:template is not idempotent 
### Summary

Setting `state:template` on a vm that is not a template works as expected: it turns the vm into a template. Next time you run it though, it fails because you can't turn a template into a template. There is no checking to see if the resource is already a template before trying to turn it into a template. 

### Issue Type

Bug Report

### Component Name

proxmox

### Ansible Version

```
$ ansible --version
ansible [core 2.16.0]
  config file = /root/homelab/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /root/py_env/lib/python3.11/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /root/py_env/bin/ansible
  python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/root/py_env/bin/python3)
  jinja version = 3.1.2
  libyaml = True
```

### Community.general Version

```
$ ansible-galaxy collection list community.general
# /root/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 8.1.0

# /root/py_env/lib/python3.11/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 8.0.2
```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed
CONFIG_FILE() = /root/homelab/ansible/ansible.cfg
DEFAULT_HOST_LIST(/root/homelab/ansible/ansible.cfg) = ['/root/homelab/ansible/inventory']
```


### OS / Environment

Proxmox

### Steps to Reproduce

```yaml (paste below)
- name "Test"
  hosts: localhost
  tasks:
    - name: "Transform into a Template"
      proxmox_kvm:
        api_user: root@pam
        api_token_id: "id"
        api_token_secret: "secret_token"
        api_host: "127.0.0.1:8006"
        vmid: <vmid>
        node: <node>
        state: template
```


### Expected Results

Running this the first time on a VM that is not a template should turn it into a template. Any subsequent time should see that it's already a template, and not do anything

### Actual Results

```console (paste below)
fatal: [localhost]: FAILED! => {"changed": false, "msg": "conversion of VM <vmid> to template failed with exception: 500 Internal Server Error: you can't convert a template to a template", "vmid": <vmid>}
```


### Code of Conduct

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


Discussion:
Files identified in the description:
* `plugins/modules/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 @UnderGreen @joshainglis @karmab
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/proxmox_kvm.py b/plugins/modules/proxmox_kvm.py
--- a/plugins/modules/proxmox_kvm.py
+++ b/plugins/modules/proxmox_kvm.py
@@ -1556,6 +1556,9 @@ def main():
         try:
             vm = proxmox.get_vm(vmid)
 
+            if vm['template'] == 1:
+                module.exit_json(changed=False, vmid=vmid, msg="VM %s is already a template" % vmid, **status)
+
             if proxmox.convert_to_template(vm, force=module.params['force'], timeout=module.params['timeout']):
                 module.exit_json(changed=True, vmid=vmid, msg="VM %s is converting to template" % vmid, **status)
         except Exception as e:


Test patch: