diff --git a/lib/ansible/modules/network/f5/bigip_gtm_facts.py b/lib/ansible/modules/network/f5/bigip_gtm_facts.py index e4b478badb5..fdae5c77122 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_facts.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_facts.py @@ -928,6 +928,16 @@ class ArgumentSpec(object): self.f5_product_name = 'bigip' +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(): if not HAS_F5SDK: raise F5ModuleError("The python f5-sdk module is required") @@ -943,8 +953,10 @@ def main(): try: 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)) diff --git a/lib/ansible/modules/network/f5/bigip_gtm_pool.py b/lib/ansible/modules/network/f5/bigip_gtm_pool.py index 36e5c2573b5..0da7df05ef7 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_pool.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_pool.py @@ -186,7 +186,6 @@ from ansible.module_utils.six import iteritems from collections import defaultdict from distutils.version import LooseVersion - try: from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError except ImportError: @@ -684,6 +683,16 @@ class ArgumentSpec(object): self.f5_product_name = 'bigip' +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(): if not HAS_F5SDK: raise F5ModuleError("The python f5-sdk module is required") @@ -703,8 +712,10 @@ def main(): try: 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)) diff --git a/lib/ansible/modules/network/f5/bigip_gtm_wide_ip.py b/lib/ansible/modules/network/f5/bigip_gtm_wide_ip.py index 6a8490d52b6..c8378a50221 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_wide_ip.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_wide_ip.py @@ -655,6 +655,16 @@ class ArgumentSpec(object): self.f5_product_name = 'bigip' +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(): if not HAS_F5SDK: raise F5ModuleError("The python f5-sdk module is required") @@ -670,8 +680,10 @@ def main(): try: 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)) diff --git a/lib/ansible/modules/network/f5/bigip_hostname.py b/lib/ansible/modules/network/f5/bigip_hostname.py index da4d8e0a89e..dd3a5bf1efc 100644 --- a/lib/ansible/modules/network/f5/bigip_hostname.py +++ b/lib/ansible/modules/network/f5/bigip_hostname.py @@ -176,6 +176,16 @@ class ArgumentSpec(object): self.f5_product_name = 'bigip' +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(): if not HAS_F5SDK: raise F5ModuleError("The python f5-sdk module is required") @@ -191,8 +201,10 @@ def main(): try: 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)) diff --git a/lib/ansible/modules/network/f5/bigip_iapp_service.py b/lib/ansible/modules/network/f5/bigip_iapp_service.py index f8db3608c44..fd40807c5d9 100644 --- a/lib/ansible/modules/network/f5/bigip_iapp_service.py +++ b/lib/ansible/modules/network/f5/bigip_iapp_service.py @@ -648,10 +648,17 @@ 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( @@ -661,10 +668,15 @@ def main(): ) 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)) diff --git a/lib/ansible/modules/network/f5/bigip_iapp_template.py b/lib/ansible/modules/network/f5/bigip_iapp_template.py index e6e8d1d1fc5..131702e493f 100644 --- a/lib/ansible/modules/network/f5/bigip_iapp_template.py +++ b/lib/ansible/modules/network/f5/bigip_iapp_template.py @@ -451,10 +451,17 @@ 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( @@ -464,11 +471,17 @@ def main(): ) 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)) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/f5/bigip_iapplx_package.py b/lib/ansible/modules/network/f5/bigip_iapplx_package.py index 60bc2c400b2..53efe2531aa 100644 --- a/lib/ansible/modules/network/f5/bigip_iapplx_package.py +++ b/lib/ansible/modules/network/f5/bigip_iapplx_package.py @@ -43,8 +43,8 @@ notes: different ways on each platform. On Debian based systems with C(apt); C(apt-get install rpm). On Mac with C(brew); C(brew install rpm). This command is already present on RedHat based systems. - - Requires BIG-IP < 12.1.0 because the required functionality is missing - on versions earlier than that. + - Requires BIG-IP >= 12.1.0 because the required functionality is missing + on versions earlier than that. requirements: - f5-sdk >= 2.2.3 - Requires BIG-IP >= 12.1.0 @@ -320,6 +320,16 @@ class ArgumentSpec(object): ] +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(): if not HAS_F5SDK: raise F5ModuleError("The python f5-sdk module is required") @@ -336,8 +346,10 @@ def main(): try: 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)) if __name__ == '__main__':