-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support proxmoxer local mode #5449
Comments
Files identified in the description: If these files are incorrect, please update the |
I think @reitermarkus started working on this in #4027, but right now the PR looks abandoned. |
Rebased #4027. Still waiting for someone to test though. |
@BioSehnsucht since you're interested in this feature, would you mind testing that PR? |
What's the easiest/quickest way to test this? Do I build a new execution environment from that PR somehow instead? I've built a custom EE before to include some things, but that was just editing the requirements yaml/txt files. From looking at PR, it might need more changes since 2 days ago there was a comment about a directory restructure ... |
Files identified in the description: If these files are incorrect, please update the |
You should be able to install @reitermarkus's branch by passing
For just trying the current version of the branch out this should be fine. The branch should more or less behave than the 5.8.0 release of community.general. |
Removing
If I re-run the otherwise exact same playbook but with using API mode, it works without specifying the above things. I have manually tested proxmox using API and local modes, and found that it handles None values differently (or perhaps, Proxmox does depending on how it's accessed). With API mode, they get sane defaults, and local mode they don't. So really, this is a problem on Proxmoxer and/or Proxmox APIs with different behavior depending on how the calls are made. In addition to tracking down the root cause further upstream in Proxmoxer and/or Proxmox to fix things, I can also think of the following "solutions": A) Document that you must specify those values clearly, and do nothing else to solve it, leaving the issue to the user to work around (would be the PR as-is plus documenting this quirk) B) Have proxmox_kvm check any kwargs that are None after the various calls to C) Kick the issue upstream to Proxmoxer and/or Proxmox to be resolved (might be done also in conjunction with a or b) For the moment, I don't have any tasks that I wouldn't be able to work around the issue by specifying the values explicitly, so I can use this PR as-is, it just requires some added values in the tasks, so I would be fine with either A, B, A+C or B+C scenarios above, but would value having this functionality sooner rather than later, with or without extra hoops to make it function on my end, so I would prefer to avoid scenario C by itself. |
I also started testing this feature and ran into same problem as @BioSehnsucht, that the None values are not handled well using local module. It seems None values are implicitly converted to strings, not removed. I'm gonna take the approach C and investigate if i'm able to change the local backend behavior on None values and do a PR there. If that's not possible, then I'd suggest approach D instead: always call proxmox api methods with I'm gonna report back when i find the difference between https and local handling of these values. |
Haa, it is actually requests module removing the values, not proxmoxer. I do not have high hopes for it, but I opened an issue in proxmoxer (proxmoxer/proxmoxer#119) asking if they're willing to do the same. If they reject, I'd be happy to help with approach D, removing the None values ourselves. Other than that, I don't think approach A and B are viable though - both would result in duplicated default values for the API. |
Adding functionality to make the API and local match would be a good addition to proxmoxer. If there are differences between the backends that has no reason to be there, removing the differences is great. In regards to the conversation of permissions and the local backend using root: If you have any other questions on authentication or proxmoxer specifically, ask away! |
@kristianheljas @jhollowe I see that the relevant PR for Proxmoxer was merged, so I guess we only need to either wait for a release or install specifically the version from Github develop branch? No changes needed on Ansible side? |
@BioSehnsucht Sorry, I forgot to ping here after the merge. I'm not sure about release schedule of proxmoxer, but yes you can install the devel version using I see no significant changes to ansible side which would affect the testing and will test the solution in the coming day myself as well. |
@kristianheljas @jhollowe @reitermarkus I tested this today, and conveniently proxmoxer has released 2.0.0, so no need to install the develop branch after all. 😄 From my limited testing (bringing up a VM and setting cloud-init in a second proxmoxer action) it appears to work as expected, so this is probably good to merge the PR #4027 on the Ansible side. |
Might have spoke too soon, I wasn't starting the VM from Ansible yet, and doing so fails when using local.
|
Looks like it is this, which was previously reported as an issue with the SSH backend and closed as being a proxmox issue ... proxmoxer/proxmoxer#117 I guess Proxmox is actually signifying this as an error when outputting JSON, when it shouldn't be. |
Since the VM actually starts, I guess I'll have to do some failed_when magic (rather not accept ALL errors, just this one error or actual success) to handle it so it doesn't fail the rest of the playbook. |
As I dig into this, I realize that @reitermarkus is already aware of the issue as I stumbled upon a forum thread discussing the problem. https://forum.proxmox.com/threads/api-bug-pvesh-create-nodes-node-qemu-output-format-json-response-format-broken.111469/ TL;DR this broke in Proxmox after a certain point, and they have yet to fix it. |
For reference, this seems to work fine, to cause the play to not fail due to the error. Of course, Ansible still thinks that the VM failed to start, even though it started. - name: Start VM
community.general.proxmox_kvm:
vmid: "{{ qemu.vmid }}"
state: started
register: start_status
failed_when:
- start_status.msg is not search('generating cloud-init ISO') |
@BioSehnsucht @reitermarkus @l00ptr We're currently starting the process of moving the proxmox modules into their own collection Since this PR effectively implements support for a second backend, it would also be a good to discuss how we want to handle different backends in the future. Maybe instead of the implicit behavior proposed here, it'd be better to have a |
@felixfontein Please close this and we can continue in |
@krauthosting why not simply move this issue over to the other repo? Also you can close it yourself by writing |
Summary
Currently, Proxmox_KVM uses Proxmoxer in API mode. Proxmoxer also supports a SSH and (since Proxmoxer 1.3.0) local mode (the main difference being that local is intended for use when you're already SSH'd into the host, and SSH performs this SSH step itself). Supporting SSH mode is probably not worthwhile since it can't do anything API mode can't, but it would be handy to support 'local' mode of operation in Proxmoxer, since it is potentially fewer places to mess with credentials. Assuming that Ansible can already SSH into the Proxmox host, then using local mode, we don't need to also include / use API credentials in the playbook (either directly or indirectly), since the playbook would already be running on the host.
Notable changes for local mode would be that
api_host
,api_user
, andapi_password
would be no longer required if using local mode. There would need to be a way to specify usingbackend='local'
to Proxmox_KVM so that it can be passed toProxmoxAPI()
(which is called fromplugins/module_utils/proxmox.py
rather than directly inplugins/modules/cloud/misc/proxmox_kvm.py
itself).The only downside I'm aware of is that I believe Ansible would be essentially accessing Proxmox as
root
rather than some other limited user, so there may be cases where it is more desirable to do it the current way, such as providing a clear log within Proxmox that the action came from Ansible rather than theroot
user. However I would like to at least have the option to trade this reduction in logging clarity for simpler playbooks, since for some of them I need to run actions directly on the Proxmox host anyways (i.e. to runqm importdisk ...
to import a cloudinit image to a VM disk, since this can't be done via the API), and it saves having to either store credentials in playbooks or pass them in somehow (via variables or vaults, etc).I propose adding a
backend
option toProxmox_KVM
, which defaults tohttps
(for normal API usage), but when set tolocal
causes theapi_*
options to optional and/or ignored rather than required (api_host
andapi_user
are normally required, the others optional) .Issue Type
Feature Idea
Component Name
proxmox_kvm
Additional Information
The first example in the docs, except using local mode (assumes that this playbook is being run on one of the nodes in the cluster - doesn't necessarily need to be the node the VM is created on):
vs the normal API mode as documented (could also be run on
"{{ VM_HOST }}"
or some other host, but probably don't want to run onall
):Code of Conduct
The text was updated successfully, but these errors were encountered: