Skip to content
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

[PR #7263/28b3da88 backport][stable-7] [proxmox] return vmid and taskid #7307

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented Sep 22, 2023

This is a backport of PR #7263 as merged into main (28b3da8).

SUMMARY

Proxmox uses an internal ID number (vmid) to refer to specific containers and virtual machines.

Ansible's community.general.proxmox module allows an LXC container to be created with an automatically-assigned vmid. However, presently (before this PR) it doesn't return the chosen ID. This means that the only way to programmatically delete a container that was programmatically created with an automatically-assigned ID involves string matching, string manipulation, and guesswork. (Some of the above logic already exists within the proxmox module, but I definitely don't trust the idea of deleting a VM based on an identifier that isn't even guaranteed unique!)

Additionally, long-lived tasks such as creating/starting/updating/deleting VMs and containers are given taskid numbers that show up in the audit log and can be used to reference the status of the task. The community.general.proxmox does use the taskid to keep track of dispatched tasks, but the module doesn't return it.

This PR adds vmid and taskid to the data returned by such actions, at least where it would make sense to do so. This way, for example, I can make a bunch of containers with automatically-assigned IDs and use Ansible's register function to reference them later in the play.

Being able to save the taskid may also help with other execution strategies, or for matching Ansible logs with Proxmox audit logs, or something. I'm not sure, really, but it seemed like a good idea to add it in while I was already there.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

proxmox

ADDITIONAL INFORMATION

This is my first contribution to Ansible, and probably my first time contributing Python code to any FOSS project! Please be gentle and be understanding if I missed anything.

* add vmid exit value

if create succeeds, we want the vmid

* fix syntax

* add vmid to return codes

* Add taskid to return, and only return vmid when it makes sense to

* add changelog fragment with temporary filename

* Add pr number to fragment

* fix PEP8 E501: line too long

* oops, I knew I still missed something...

* Update 7263-proxmox-return-vmid-and-taskid.yaml

Co-authored-by: Felix Fontein <felix@fontein.de>

* removed taskid from places it's not defined

* finally fixed sanity test errors

Okay, so maybe just waiting for CI to run the tests was a terrible idea.

I installed `inotifywait`, set up a venv for the tests, and in my
editor's terminal pane I ran the following, letting it run every save
until it exited:

    until ansible-test sanity proxmox ; do
        inotifywait --event modify plugins/modules/proxmox.py
    done

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 28b3da8)
@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added backport feature This issue/PR relates to a feature request module module needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor plugins plugin (any type) and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Sep 22, 2023
@felixfontein felixfontein merged commit e8861ca into stable-7 Sep 22, 2023
@felixfontein felixfontein deleted the patchback/backports/stable-7/28b3da88a9b05743811452f2fcb6271249dac8f7/pr-7263 branch September 22, 2023 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request module module new_contributor Help guide this first time contributor plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants