From 79fb3e9852531f4476105031138c0f91fce8f9f3 Mon Sep 17 00:00:00 2001 From: Ajpantuso Date: Fri, 19 Mar 2021 14:18:05 -0400 Subject: [PATCH] Adding purge parameter to proxmox for use with lxc delete requests (#2013) * added purge as optional module parameter * Adding changelog fragment * Adding version to documentation for purge Co-authored-by: Felix Fontein * Updating changelog Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- .../fragments/2013-proxmox-purge-parameter.yml | 3 +++ plugins/modules/cloud/misc/proxmox.py | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/2013-proxmox-purge-parameter.yml diff --git a/changelogs/fragments/2013-proxmox-purge-parameter.yml b/changelogs/fragments/2013-proxmox-purge-parameter.yml new file mode 100644 index 0000000000..6c681e5a19 --- /dev/null +++ b/changelogs/fragments/2013-proxmox-purge-parameter.yml @@ -0,0 +1,3 @@ +--- +minor_changes: +- proxmox - added ``purge`` module parameter for use when deleting lxc's with HA options (https://github.com/ansible-collections/community.general/pull/2013). diff --git a/plugins/modules/cloud/misc/proxmox.py b/plugins/modules/cloud/misc/proxmox.py index b5040bc659..422c108c35 100644 --- a/plugins/modules/cloud/misc/proxmox.py +++ b/plugins/modules/cloud/misc/proxmox.py @@ -123,6 +123,15 @@ options: - with states C(stopped) , C(restarted) allow to force stop instance type: bool default: 'no' + purge: + description: + - Remove container from all related configurations. + - For example backup jobs, replication jobs, or HA. + - Related ACLs and Firewall entries will always be removed. + - Used with state C(absent). + type: bool + default: false + version_added: 2.3.0 state: description: - Indicate desired state of the instance @@ -506,6 +515,7 @@ def main(): searchdomain=dict(), timeout=dict(type='int', default=30), force=dict(type='bool', default=False), + purge=dict(type='bool', default=False), state=dict(default='present', choices=['present', 'absent', 'stopped', 'started', 'restarted']), pubkey=dict(type='str', default=None), unprivileged=dict(type='bool', default=False), @@ -686,7 +696,13 @@ def main(): if getattr(proxmox.nodes(vm[0]['node']), VZ_TYPE)(vmid).status.current.get()['status'] == 'mounted': module.exit_json(changed=False, msg="VM %s is mounted. Stop it with force option before deletion." % vmid) - taskid = getattr(proxmox.nodes(vm[0]['node']), VZ_TYPE).delete(vmid) + delete_params = {} + + if module.params['purge']: + delete_params['purge'] = 1 + + taskid = getattr(proxmox.nodes(vm[0]['node']), VZ_TYPE).delete(vmid, **delete_params) + while timeout: if (proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['status'] == 'stopped' and proxmox.nodes(vm[0]['node']).tasks(taskid).status.get()['exitstatus'] == 'OK'):