From 19e4b7d3abdd91326917f79a3937d1b3c7dd88c6 Mon Sep 17 00:00:00 2001 From: Yvan Watchman Date: Mon, 12 Sep 2022 20:31:30 +0200 Subject: [PATCH] =?UTF-8?q?add=20a=20couple=20conditionals=20to=20make=20s?= =?UTF-8?q?ure=20updating=20can=20be=20done=20with=20vmid=E2=80=A6=20(#520?= =?UTF-8?q?6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add a couple conditionals to make sure updating can be done with vmid only * add changelog to PR * replace conditional with any * any takes list * fix next conditional * Update changelogs/fragments/5206-proxmox-conditional-vmid.yml Co-authored-by: Felix Fontein * capitalize VM and remove conditional for name requirement upon creation * Fix URL destroyed by GitHub. Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Yvan E. Watchman Co-authored-by: Felix Fontein Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- changelogs/fragments/5206-proxmox-conditional-vmid.yml | 3 +++ plugins/modules/cloud/misc/proxmox_kvm.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/5206-proxmox-conditional-vmid.yml diff --git a/changelogs/fragments/5206-proxmox-conditional-vmid.yml b/changelogs/fragments/5206-proxmox-conditional-vmid.yml new file mode 100644 index 0000000000..b558d137c3 --- /dev/null +++ b/changelogs/fragments/5206-proxmox-conditional-vmid.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - proxmox_kvm - replace new condition with proper condition to allow for using ``vmid`` on update (https://github.com/ansible-collections/community.general/pull/5206). diff --git a/plugins/modules/cloud/misc/proxmox_kvm.py b/plugins/modules/cloud/misc/proxmox_kvm.py index 15a59be815..dc2d6e5aae 100644 --- a/plugins/modules/cloud/misc/proxmox_kvm.py +++ b/plugins/modules/cloud/misc/proxmox_kvm.py @@ -1243,8 +1243,10 @@ def main(): module.exit_json(changed=False, vmid=vmid, msg="VM with vmid <%s> already exists" % vmid) elif proxmox.get_vmid(name, ignore_missing=True) and not (update or clone): module.exit_json(changed=False, vmid=proxmox.get_vmid(name), msg="VM with name <%s> already exists" % name) - elif (not node) or (not name): - module.fail_json(msg='node, name is mandatory for creating/updating vm') + elif not node: + module.fail.json(msg='node is mandatory for creating/updating VM') + elif update and not any([vmid, name]): + module.fail_json(msg='vmid or name is mandatory for updating VM') elif not proxmox.get_node(node): module.fail_json(msg="node '%s' does not exist in cluster" % node)