From 554ffd70f59db1662a309e17dc2beca57c80bb96 Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Fri, 22 Dec 2017 11:40:20 -0800 Subject: [PATCH] Adds token cleanup to bigip irules (#34203) Token cleanup helps keep the bigip from getting wedged --- lib/ansible/modules/network/f5/bigip_irule.py | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/network/f5/bigip_irule.py b/lib/ansible/modules/network/f5/bigip_irule.py index 7538c8c1948..a466c90c54f 100644 --- a/lib/ansible/modules/network/f5/bigip_irule.py +++ b/lib/ansible/modules/network/f5/bigip_irule.py @@ -403,24 +403,36 @@ class ArgumentSpec(object): self.f5_product_name = 'bigip' -def main(): - if not HAS_F5SDK: - raise F5ModuleError("The python f5-sdk module is required") +def cleanup_tokens(client): + try: + resource = client.api.shared.authz.tokens_s.token.load( + name=client.api.icrs.token + ) + resource.delete() + except Exception: + pass + +def main(): spec = ArgumentSpec() client = AnsibleF5Client( argument_spec=spec.argument_spec, - mutually_exclusive=spec.mutually_exclusive, supports_check_mode=spec.supports_check_mode, - f5_product_name=spec.f5_product_name + f5_product_name=spec.f5_product_name, + mutually_exclusive=spec.mutually_exclusive, ) try: + if not HAS_F5SDK: + raise F5ModuleError("The python f5-sdk module is required") + mm = ModuleManager(client) results = mm.exec_module() + cleanup_tokens(client) client.module.exit_json(**results) except F5ModuleError as e: + cleanup_tokens(client) client.module.fail_json(msg=str(e))