diff --git a/lib/ansible/modules/network/f5/bigip_gtm_monitor_bigip.py b/lib/ansible/modules/network/f5/bigip_gtm_monitor_bigip.py index e844f81242..e2e317d84e 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_monitor_bigip.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_monitor_bigip.py @@ -191,6 +191,7 @@ try: from library.module_utils.network.f5.common import AnsibleF5Parameters from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -202,17 +203,12 @@ except ImportError: from ansible.module_utils.network.f5.common import AnsibleF5Parameters from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import f5_argument_spec + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -311,12 +307,11 @@ class ModuleParameters(Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: + if self._values['ip'] in ['*', '0.0.0.0']: + return '*' + elif is_valid_ip(self._values['ip']): + return self._values['ip'] + else: raise F5ModuleError( "The provided 'ip' parameter is not an IP address." ) @@ -607,8 +602,6 @@ def main(): ) if not HAS_F5SDK: module.fail_json(msg="The python f5-sdk module is required") - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: client = F5Client(**module.params) diff --git a/lib/ansible/modules/network/f5/bigip_gtm_monitor_external.py b/lib/ansible/modules/network/f5/bigip_gtm_monitor_external.py index 824a0ddf39..a3d5b235c5 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_monitor_external.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_monitor_external.py @@ -163,6 +163,7 @@ try: from library.module_utils.network.f5.common import fq_name from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.common import compare_dictionary + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -176,17 +177,12 @@ except ImportError: from ansible.module_utils.network.f5.common import fq_name from ansible.module_utils.network.f5.common import f5_argument_spec from ansible.module_utils.network.f5.common import compare_dictionary + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -256,12 +252,11 @@ class Parameters(AnsibleF5Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: + if self._values['ip'] in ['*', '0.0.0.0']: + return '*' + elif is_valid_ip(self._values['ip']): + return self._values['ip'] + else: raise F5ModuleError( "The provided 'ip' parameter is not an IP address." ) diff --git a/lib/ansible/modules/network/f5/bigip_gtm_monitor_firepass.py b/lib/ansible/modules/network/f5/bigip_gtm_monitor_firepass.py index c92de5c040..780a4ed4f4 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_monitor_firepass.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_monitor_firepass.py @@ -228,6 +228,7 @@ try: from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import fq_name from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -240,17 +241,12 @@ except ImportError: from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import fq_name from ansible.module_utils.network.f5.common import f5_argument_spec + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -351,12 +347,11 @@ class ModuleParameters(Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: + if self._values['ip'] in ['*', '0.0.0.0']: + return '*' + elif is_valid_ip(self._values['ip']): + return self._values['ip'] + else: raise F5ModuleError( "The provided 'ip' parameter is not an IP address." ) @@ -729,8 +724,6 @@ def main(): ) if not HAS_F5SDK: module.fail_json(msg="The python f5-sdk module is required") - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: client = F5Client(**module.params) diff --git a/lib/ansible/modules/network/f5/bigip_gtm_monitor_http.py b/lib/ansible/modules/network/f5/bigip_gtm_monitor_http.py index 22efd630e4..0dd9594f88 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_monitor_http.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_monitor_http.py @@ -237,6 +237,7 @@ try: from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import fq_name from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -249,17 +250,12 @@ except ImportError: from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import fq_name from ansible.module_utils.network.f5.common import f5_argument_spec + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -377,12 +373,11 @@ class ModuleParameters(Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: + if self._values['ip'] in ['*', '0.0.0.0']: + return '*' + elif is_valid_ip(self._values['ip']): + return self._values['ip'] + else: raise F5ModuleError( "The provided 'ip' parameter is not an IP address." ) @@ -774,8 +769,6 @@ def main(): ) if not HAS_F5SDK: module.fail_json(msg="The python f5-sdk module is required") - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: client = F5Client(**module.params) diff --git a/lib/ansible/modules/network/f5/bigip_gtm_monitor_https.py b/lib/ansible/modules/network/f5/bigip_gtm_monitor_https.py index bbfe41e800..3d3901e802 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_monitor_https.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_monitor_https.py @@ -276,6 +276,7 @@ try: from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import fq_name from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -288,17 +289,12 @@ except ImportError: from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import fq_name from ansible.module_utils.network.f5.common import f5_argument_spec + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -439,12 +435,11 @@ class ModuleParameters(Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: + if self._values['ip'] in ['*', '0.0.0.0']: + return '*' + elif is_valid_ip(self._values['ip']): + return self._values['ip'] + else: raise F5ModuleError( "The provided 'ip' parameter is not an IP address." ) @@ -894,8 +889,6 @@ def main(): ) if not HAS_F5SDK: module.fail_json(msg="The python f5-sdk module is required") - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: client = F5Client(**module.params) diff --git a/lib/ansible/modules/network/f5/bigip_gtm_monitor_tcp.py b/lib/ansible/modules/network/f5/bigip_gtm_monitor_tcp.py index f5b8276a79..901b1d0e9d 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_monitor_tcp.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_monitor_tcp.py @@ -221,6 +221,7 @@ try: from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import fq_name from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -233,17 +234,12 @@ except ImportError: from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import fq_name from ansible.module_utils.network.f5.common import f5_argument_spec + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -355,15 +351,13 @@ class ModuleParameters(Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: - raise F5ModuleError( - "The provided 'ip' parameter is not an IP address." - ) + elif self._values['ip'] in ['*', '0.0.0.0']: + return '*' + elif is_valid_ip(self._values['ip']): + return self._values['ip'] + raise F5ModuleError( + "The provided 'ip' parameter is not an IP address." + ) @property def parent(self): @@ -737,8 +731,6 @@ def main(): ) if not HAS_F5SDK: module.fail_json(msg="The python f5-sdk module is required") - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: client = F5Client(**module.params) diff --git a/lib/ansible/modules/network/f5/bigip_gtm_monitor_tcp_half_open.py b/lib/ansible/modules/network/f5/bigip_gtm_monitor_tcp_half_open.py index ae69797347..cc9fc16b4c 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_monitor_tcp_half_open.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_monitor_tcp_half_open.py @@ -196,6 +196,7 @@ try: from library.module_utils.network.f5.common import AnsibleF5Parameters from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.ipaddress import is_valid_ip try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -207,17 +208,12 @@ except ImportError: from ansible.module_utils.network.f5.common import AnsibleF5Parameters from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import f5_argument_spec + from ansible.module_utils.network.f5.ipaddress import is_valid_ip try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: HAS_F5SDK = False -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - class Parameters(AnsibleF5Parameters): api_map = { @@ -344,12 +340,11 @@ class ModuleParameters(Parameters): def ip(self): if self._values['ip'] is None: return None - try: - if self._values['ip'] in ['*', '0.0.0.0']: - return '*' - result = str(netaddr.IPAddress(self._values['ip'])) - return result - except netaddr.core.AddrFormatError: + if self._values['ip'] in ['*', '0.0.0.0']: + return '*' + elif is_valid_ip(self._values['ip']): + return self._values['ip'] + else: raise F5ModuleError( "The provided 'ip' parameter is not an IP address." ) @@ -651,8 +646,6 @@ def main(): ) if not HAS_F5SDK: module.fail_json(msg="The python f5-sdk module is required") - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: client = F5Client(**module.params)