Skip to content

Commit 3f82ab6

Browse files
committed
proxmox_zone: add missing exception handling for zone_preent()
1 parent 57c7e7d commit 3f82ab6

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

plugins/modules/proxmox_zone.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,6 @@ def zone_present(self, force, **kwargs):
444444
if type != available_zones[zone]['type']:
445445
self.release_lock(lock)
446446
self.module.fail_json(
447-
lock=lock,
448447
msg=f'zone {zone} exists with different type and we cannot change type post fact.'
449448
)
450449
else:
@@ -455,11 +454,17 @@ def zone_present(self, force, **kwargs):
455454
changed=False, zone=zone, msg=f'Zone {zone} already exists and force is false!'
456455
)
457456
else:
458-
self.proxmox_api.cluster().sdn().zones().post(**kwargs)
459-
self.apply_sdn_changes_and_release_lock(lock)
460-
self.module.exit_json(
461-
changed=True, zone=zone, msg=f'Created new Zone - {zone}'
462-
)
457+
try:
458+
self.proxmox_api.cluster().sdn().zones().post(**kwargs)
459+
self.apply_sdn_changes_and_release_lock(lock)
460+
self.module.exit_json(
461+
changed=True, zone=zone, msg=f'Created new Zone - {zone}'
462+
)
463+
except Exception as e:
464+
self.rollback_sdn_changes_and_release_lock(lock)
465+
self.module.fail_json(
466+
msg=f'Failed to create zone {zone}'
467+
)
463468

464469
def zone_update(self, **kwargs):
465470
available_zones = {x['zone']: {'type': x["type"], 'digest': x['digest']} for x in self.get_zones()}

0 commit comments

Comments
 (0)