Repository: ansible-collections/community.general

Issue:
proxmox: password required for lxc even if pubkey specified
### Summary

A `password` is required even if `pubkey` is specified

### Issue Type

Bug Report

### Component Name

proxmox

### Ansible Version

```
2.10.1
```

### Configuration

_No response_

### OS / Environment

_No response_

### Steps To Reproduce

```paste below
- name: Create LXC
  community.general.proxmox:
    ... specify your settings
    pubkey: 'ssh-rsa ..'
```


### Expected Results

Successful LXC creation

### Actual Results

```paste below
The full traceback is:
  File "/tmp/ansible_community.general.proxmox_payload_q6kwjc3v/ansible_community.general.proxmox_payload.zip/ansible/module_utils/basic.py", line 1660, in _check_required_if
    check_required_if(spec, param)
  File "/tmp/ansible_community.general.proxmox_payload_q6kwjc3v/ansible_community.general.proxmox_payload.zip/ansible/module_utils/common/validation.py", line 275, in check_required_if
    raise TypeError(to_native(msg))
....
    "msg": "state is present but all of the following are missing: password"
```





Discussion:
Files identified in the description:
* [`plugins/modules/cloud/misc/proxmox_snap.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/cloud/misc/proxmox_snap.py)

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 --->
cc @Aversiste @Thulium-Drake @joshainglis @karmab
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
!component =plugins/modules/cloud/misc/proxmox.py

@tabic I think that `pubkey` is not for authentication, but for configuring an instance. You need to specify username/password for authentication, otherwise the module cannot talk to proxmox.
Files identified in the description:
* [`plugins/modules/cloud/misc/proxmox.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/cloud/misc/proxmox.py)

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 --->
cc @UnderGreen
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
In the web UI a public key can be specified instead of a password.
From https://pve.proxmox.com/wiki/Linux_Container#pct_settings

> Password: the root password of the container
> SSH Public Key: a public key for connecting to the root account over SSH
Just checked: The specified `pubkey` gets added to the lxc container but this module still requires a `password`
Ah, sorry, I misunderstood - you're talking about the instance password, not the API password (`api_password`). You're right, the module seems to require `password` to be present. Maybe it should require that at least one of `password` and `pubkey` is specified - that depends on the API though, whether it accepts only `pubkey` (though I'd think it would if the web UI accepts that).
It looks like supplying only the pubkey successfully creates a lxc instance if the requirements are changed to the following:
```python
required_if=[('state', 'present', ['node', 'hostname', 'ostemplate']),
                      ('state', 'present', ['password', 'pubkey'], True)],
```

However I'm not really setup to run a regression for this module nor am I sure that's the optimal way to re-define the requirements.
@Ajpantuso that change should be safe. The worst that can happen is that there is an edge case where `pubkey` is not enough, and proxmox will return an error (instead of the module before invoking proxmox). Feel free to create a bugfix PR for this!

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
@@ -17,7 +17,6 @@
   password:
     description:
       - the instance root password
-      - required only for C(state=present)
     type: str
   hostname:
     description:
@@ -514,7 +513,7 @@ def main():
             hookscript=dict(type='str'),
             proxmox_default_behavior=dict(type='str', choices=['compatibility', 'no_defaults']),
         ),
-        required_if=[('state', 'present', ['node', 'hostname', 'password', 'ostemplate'])],
+        required_if=[('state', 'present', ['node', 'hostname', 'ostemplate'])],
         required_together=[('api_token_id', 'api_token_secret')],
         required_one_of=[('api_password', 'api_token_id')],
     )


Test patch: