1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[PR #6981/f9448574 backport][stable-6] [proxmox_kvm] Don't create VM if name is used without vmid (#7003)

* [proxmox_kvm] Don't create VM if name is used without vmid (#6981)

* [proxmox_kvm] Don't create VM if name is used without vmid

* Add changelog and unit tests

(cherry picked from commit f9448574bd)

* Remove semantic markup
This commit is contained in:
Sergei Antipov 2023-07-24 02:27:35 -04:00 committed by GitHub
parent 201f49acd9
commit 43c1d9f66c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- proxmox_kvm - when ``name`` option is provided without ``vmid`` and VM with that name already exists then no new VM will be created (https://github.com/ansible-collections/community.general/issues/6911, https://github.com/ansible-collections/community.general/pull/6981).

View file

@ -281,8 +281,9 @@ options:
type: int type: int
name: name:
description: description:
- Specifies the VM name. Only used on the configuration web interface. - Specifies the VM name. Name could be non-unique across the cluster.
- Required only for C(state=present). - Required only for I(state=present).
- With I(state=present) if I(vmid) not provided and VM with name exists in the cluster then no changes will be made.
type: str type: str
nameservers: nameservers:
description: description:
@ -1210,6 +1211,10 @@ def main():
# the cloned vm name or retrieve the next free VM id from ProxmoxAPI. # the cloned vm name or retrieve the next free VM id from ProxmoxAPI.
if not vmid: if not vmid:
if state == 'present' and not update and not clone and not delete and not revert: if state == 'present' and not update and not clone and not delete and not revert:
existing_vmid = proxmox.get_vmid(name, ignore_missing=True)
if existing_vmid:
vmid = existing_vmid
else:
try: try:
vmid = proxmox.get_nextvmid() vmid = proxmox.get_nextvmid()
except Exception: except Exception: