community.general icon indicating copy to clipboard operation
community.general copied to clipboard

proxmox: plugin gets very angry if remote proxmoxer is not new enough: TypeError: __init__() got an unexpected keyword argument 'token_name'

Open grinapo opened this issue 1 year ago • 2 comments

Summary

Proxmox expects some specific version of proxmoxer on the repote but does not verify it. It causes mismatched a bit cryptic parameter errors.

Issue Type

Bug Report

Component Name

https://github.com/ansible-collections/community.general/blob/main/plugins/modules/cloud/misc/proxmox.py

Ansible Version

ansible [core 2.13.4]

Community.general Version

community.general 5.6.0

Configuration

No response

OS / Environment

Debian/bookworm

Steps to Reproduce

Use API tokens when remote proxmoxer is python3-proxmoxer v1.0.3-2 or similar. Fail.

Expected Results

The problem is that old proxmoxer https backend doesn't handle tokens:

class Backend(object):
    def __init__(self, host, user, password, port=8006, verify_ssl=True,
                 mode='json', timeout=5, auth_token=None, csrf_token=None):

while new one does

class Backend(object):
    def __init__(self, host, user=None, password=None, otp=None, port=None,
                 verify_ssl=True, mode='json', timeout=5, auth_token=None,
                 csrf_token=None, token_name=None, token_value=None, service='PVE'):

I'd expect either verifying dependant module version/API or handle the error gracefully.

Actual Results

Traceback (most recent call last):
  File "/tmp/ansible_community.general.proxmox_payload_xgpdvxe0/ansible_community.general.proxmox_payload.zip/ansible_collections/community/general/plugins/module_utils/proxmox.py", line 101, in _connect
    return ProxmoxAPI(api_host, verify_ssl=validate_certs, **auth_args)
  File "/usr/lib/python3/dist-packages/proxmoxer/core.py", line 106, in __init__
    self._backend = importlib.import_module('.backends.%s' % backend, 'proxmoxer').Backend(host, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'token_name'

Code of Conduct

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

grinapo avatar Oct 15 '22 10:10 grinapo

Files identified in the description:

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

ansibullbot avatar Oct 15 '22 10:10 ansibullbot

cc @Ajpantuso @Thulium-Drake @UnderGreen @joshainglis @karmab @tleguern click here for bot help

ansibullbot avatar Oct 15 '22 10:10 ansibullbot

I am having the same situation. In my case, I installed the latest version of proxmoxer via pip in my laptop and installed the python3-proxmoxer package version 1.0.3-2 on my server running Debian 11 Bullseye (my mistake). When I finished testing the playbook and wanted to run it remotely on the server, this error appeared:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: __init__() got an unexpected keyword argument 'token_name'
fatal: [proxmox3.domain.com]: FAILED! => {"changed": false, "msg": "__init__() got an unexpected keyword argument 'token_name'"}

While I understand that a more modern version is required in the server (I'll start working on that today) I agree with @grinapo that a more elegant, precise and explanatory message should be given back to the user (e.g. "The version of proxmoxer that you are running on the host is too old. At least version X.Y is required").

Thanks in advanced.

jsabater avatar Nov 02 '22 07:11 jsabater