@ -33,12 +33,7 @@ options:
- Perform regex filter of response . Filtering is done on the name of
- Perform regex filter of response . Filtering is done on the name of
the resource . Valid filters are anything that can be provided to
the resource . Valid filters are anything that can be provided to
Python ' s C(re) module.
Python ' s C(re) module.
notes :
- Requires the f5 - sdk Python package on the host . This is as easy as
pip install f5 - sdk
extends_documentation_fragment : f5
extends_documentation_fragment : f5
requirements :
- f5 - sdk
author :
author :
- Tim Rupp ( @caphrim007 )
- Tim Rupp ( @caphrim007 )
'''
'''
@ -173,18 +168,45 @@ virtual_server:
import re
import re
from ansible . module_utils . basic import AnsibleModule
HAS_DEVEL_IMPORTS = False
try :
# Sideband repository used for dev
from library . module_utils . network . f5 . bigip import HAS_F5SDK
from library . module_utils . network . f5 . bigip import F5Client
from library . module_utils . network . f5 . common import F5ModuleError
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 fqdn_name
from library . module_utils . network . f5 . common import f5_argument_spec
try :
from library . module_utils . network . f5 . common import iControlUnexpectedHTTPError
except ImportError :
HAS_F5SDK = False
HAS_DEVEL_IMPORTS = True
except ImportError :
# Upstream Ansible
from ansible . module_utils . network . f5 . bigip import HAS_F5SDK
from ansible . module_utils . network . f5 . bigip import F5Client
from ansible . module_utils . network . f5 . common import F5ModuleError
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 fqdn_name
from ansible . module_utils . network . f5 . common import f5_argument_spec
try :
from ansible . module_utils . network . f5 . common import iControlUnexpectedHTTPError
except ImportError :
HAS_F5SDK = False
try :
try :
import json
import json
except ImportError :
except ImportError :
import simplejson as json
import simplejson as json
from ansible . module_utils . f5_utils import AnsibleF5Client
from ansible . module_utils . f5_utils import AnsibleF5Parameters
from ansible . module_utils . f5_utils import HAS_F5SDK
from ansible . module_utils . f5_utils import F5ModuleError
from ansible . module_utils . parsing . convert_bool import BOOLEANS_TRUE
from ansible . module_utils . parsing . convert_bool import BOOLEANS_TRUE
from ansible . module_utils . six import iteritems
from ansible . module_utils . six import iteritems
from collections import defaultdict
from distutils . version import LooseVersion
from distutils . version import LooseVersion
try :
try :
@ -195,8 +217,11 @@ except ImportError:
class BaseManager ( object ) :
class BaseManager ( object ) :
def __init__ ( self , client ) :
def __init__ ( self , * args , * * kwargs ) :
self . client = client
self . module = kwargs . get ( ' module ' , None )
self . client = kwargs . get ( ' client ' , None )
self . kwargs = kwargs
self . types = dict (
self . types = dict (
a_s = ' a ' ,
a_s = ' a ' ,
aaaas = ' aaaa ' ,
aaaas = ' aaaa ' ,
@ -269,10 +294,6 @@ class TypedManager(BaseManager):
class Parameters ( AnsibleF5Parameters ) :
class Parameters ( AnsibleF5Parameters ) :
def __init__ ( self , params = None ) :
super ( Parameters , self ) . __init__ ( params )
self . _values [ ' __warnings ' ] = [ ]
@property
@property
def include ( self ) :
def include ( self ) :
requested = self . _values [ ' include ' ]
requested = self . _values [ ' include ' ]
@ -296,36 +317,7 @@ class Parameters(AnsibleF5Parameters):
return requested
return requested
class BaseParameters ( AnsibleF5Parameters ) :
class BaseParameters ( Parameters ) :
def __init__ ( self , params = None ) :
self . _values = defaultdict ( lambda : None )
if params :
self . update ( params = params )
self . _values [ ' __warnings ' ] = [ ]
def update ( self , params = None ) :
if params :
for k , v in iteritems ( params ) :
if self . api_map is not None and k in self . api_map :
map_key = self . api_map [ k ]
else :
map_key = k
# Handle weird API parameters like `dns.proxy.__iter__` by
# using a map provided by the module developer
class_attr = getattr ( type ( self ) , map_key , None )
if isinstance ( class_attr , property ) :
# There is a mapped value for the api_map key
if class_attr . fset is None :
# If the mapped value does not have an associated setter
self . _values [ map_key ] = v
else :
# The mapped value has a setter
setattr ( self , map_key , v )
else :
# If the mapped value is not a @property
self . _values [ map_key ] = v
@property
@property
def enabled ( self ) :
def enabled ( self ) :
if self . _values [ ' enabled ' ] is None :
if self . _values [ ' enabled ' ] is None :
@ -697,6 +689,12 @@ class ServerParameters(BaseParameters):
class PoolFactManager ( BaseManager ) :
class PoolFactManager ( BaseManager ) :
def __init__ ( self , * args , * * kwargs ) :
self . module = kwargs . get ( ' module ' , None )
self . client = kwargs . get ( ' client ' , None )
super ( PoolFactManager , self ) . __init__ ( * * kwargs )
self . kwargs = kwargs
def exec_module ( self ) :
def exec_module ( self ) :
if self . version_is_less_than_12 ( ) :
if self . version_is_less_than_12 ( ) :
manager = self . get_manager ( ' untyped ' )
manager = self . get_manager ( ' untyped ' )
@ -708,15 +706,17 @@ class PoolFactManager(BaseManager):
def get_manager ( self , type ) :
def get_manager ( self , type ) :
if type == ' typed ' :
if type == ' typed ' :
return TypedPoolFactManager ( self . client )
return TypedPoolFactManager ( * * self . kwargs )
elif type == ' untyped ' :
elif type == ' untyped ' :
return UntypedPoolFactManager ( self . client )
return UntypedPoolFactManager ( * * self . kwargs )
class TypedPoolFactManager ( TypedManager ) :
class TypedPoolFactManager ( TypedManager ) :
def __init__ ( self , client ) :
def __init__ ( self , * args , * * kwargs ) :
super ( TypedPoolFactManager , self ) . __init__ ( client )
self . module = kwargs . get ( ' module ' , None )
self . want = PoolParameters ( self . client . module . params )
self . client = kwargs . get ( ' client ' , None )
super ( TypedPoolFactManager , self ) . __init__ ( * * kwargs )
self . want = PoolParameters ( params = self . module . params )
def read_facts ( self , collection ) :
def read_facts ( self , collection ) :
results = [ ]
results = [ ]
@ -740,9 +740,11 @@ class TypedPoolFactManager(TypedManager):
class UntypedPoolFactManager ( UntypedManager ) :
class UntypedPoolFactManager ( UntypedManager ) :
def __init__ ( self , client ) :
def __init__ ( self , * args , * * kwargs ) :
super ( UntypedPoolFactManager , self ) . __init__ ( client )
self . client = kwargs . get ( ' client ' , None )
self . want = PoolParameters ( self . client . module . params )
self . module = kwargs . get ( ' module ' , None )
super ( UntypedPoolFactManager , self ) . __init__ ( * * kwargs )
self . want = PoolParameters ( params = self . module . params )
def read_facts ( self ) :
def read_facts ( self ) :
results = [ ]
results = [ ]
@ -775,15 +777,17 @@ class WideIpFactManager(BaseManager):
def get_manager ( self , type ) :
def get_manager ( self , type ) :
if type == ' typed ' :
if type == ' typed ' :
return TypedWideIpFactManager ( self . client )
return TypedWideIpFactManager ( * * self . kwargs )
elif type == ' untyped ' :
elif type == ' untyped ' :
return UntypedWideIpFactManager ( self . client )
return UntypedWideIpFactManager ( * * self . kwargs )
class TypedWideIpFactManager ( TypedManager ) :
class TypedWideIpFactManager ( TypedManager ) :
def __init__ ( self , client ) :
def __init__ ( self , * args , * * kwargs ) :
super ( TypedWideIpFactManager , self ) . __init__ ( client )
self . client = kwargs . get ( ' client ' , None )
self . want = WideIpParameters ( self . client . module . params )
self . module = kwargs . get ( ' module ' , None )
super ( TypedWideIpFactManager , self ) . __init__ ( * * kwargs )
self . want = WideIpParameters ( params = self . module . params )
def read_facts ( self , collection ) :
def read_facts ( self , collection ) :
results = [ ]
results = [ ]
@ -806,9 +810,11 @@ class TypedWideIpFactManager(TypedManager):
class UntypedWideIpFactManager ( UntypedManager ) :
class UntypedWideIpFactManager ( UntypedManager ) :
def __init__ ( self , client ) :
def __init__ ( self , * args , * * kwargs ) :
super ( UntypedWideIpFactManager , self ) . __init__ ( client )
self . client = kwargs . get ( ' client ' , None )
self . want = WideIpParameters ( self . client . module . params )
self . module = kwargs . get ( ' module ' , None )
super ( UntypedWideIpFactManager , self ) . __init__ ( * * kwargs )
self . want = WideIpParameters ( params = self . module . params )
def read_facts ( self ) :
def read_facts ( self ) :
results = [ ]
results = [ ]
@ -829,9 +835,11 @@ class UntypedWideIpFactManager(UntypedManager):
class ServerFactManager ( UntypedManager ) :
class ServerFactManager ( UntypedManager ) :
def __init__ ( self , client ) :
def __init__ ( self , * args , * * kwargs ) :
super ( ServerFactManager , self ) . __init__ ( client )
self . client = kwargs . get ( ' client ' , None )
self . want = ServerParameters ( self . client . module . params )
self . module = kwargs . get ( ' module ' , None )
super ( ServerFactManager , self ) . __init__ ( * * kwargs )
self . want = ServerParameters ( params = self . module . params )
def exec_module ( self ) :
def exec_module ( self ) :
facts = super ( ServerFactManager , self ) . exec_module ( )
facts = super ( ServerFactManager , self ) . exec_module ( )
@ -857,9 +865,11 @@ class ServerFactManager(UntypedManager):
class ModuleManager ( object ) :
class ModuleManager ( object ) :
def __init__ ( self , client ) :
def __init__ ( self , * args , * * kwargs ) :
self . client = client
self . module = kwargs . get ( ' module ' , None )
self . want = Parameters ( self . client . module . params )
self . client = kwargs . get ( ' client ' , None )
self . kwargs = kwargs
self . want = Parameters ( params = self . module . params )
def exec_module ( self ) :
def exec_module ( self ) :
if not self . gtm_provisioned ( ) :
if not self . gtm_provisioned ( ) :
@ -889,7 +899,7 @@ class ModuleManager(object):
if self . want :
if self . want :
warnings + = self . want . _values . get ( ' __warnings ' , [ ] )
warnings + = self . want . _values . get ( ' __warnings ' , [ ] )
for warning in warnings :
for warning in warnings :
self . client. module. deprecate (
self . module. deprecate (
msg = warning [ ' msg ' ] ,
msg = warning [ ' msg ' ] ,
version = warning [ ' version ' ]
version = warning [ ' version ' ]
)
)
@ -903,11 +913,11 @@ class ModuleManager(object):
def get_manager ( self , which ) :
def get_manager ( self , which ) :
if ' pool ' == which :
if ' pool ' == which :
return PoolFactManager ( self . client )
return PoolFactManager ( * * self . kwargs )
if ' wide_ip ' == which :
if ' wide_ip ' == which :
return WideIpFactManager ( self . client )
return WideIpFactManager ( * * self . kwargs )
if ' server ' == which :
if ' server ' == which :
return ServerFactManager ( self . client )
return ServerFactManager ( * * self . kwargs )
def gtm_provisioned ( self ) :
def gtm_provisioned ( self ) :
resource = self . client . api . tm . sys . dbs . db . load (
resource = self . client . api . tm . sys . dbs . db . load (
@ -921,43 +931,34 @@ class ModuleManager(object):
class ArgumentSpec ( object ) :
class ArgumentSpec ( object ) :
def __init__ ( self ) :
def __init__ ( self ) :
self . supports_check_mode = False
self . supports_check_mode = False
self . argument_spec = dict (
argument_spec = dict (
include = dict ( type = ' list ' , required = True ) ,
include = dict ( type = ' list ' , required = True ) ,
filter = dict ( type = ' str ' , required = False )
filter = dict ( )
)
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 ( )
self . argument_spec = { }
except Exception :
self . argument_spec . update ( f5_argument_spec )
pass
self . argument_spec . update ( argument_spec )
def main ( ) :
def main ( ) :
if not HAS_F5SDK :
raise F5ModuleError ( " The python f5-sdk module is required " )
spec = ArgumentSpec ( )
spec = ArgumentSpec ( )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = spec . argument_spec ,
argument_spec = spec . argument_spec ,
supports_check_mode = spec . supports_check_mode ,
supports_check_mode = spec . supports_check_mode
f5_product_name = spec . f5_product_name ,
)
)
if not HAS_F5SDK :
module . fail_json ( msg = " The python f5-sdk module is required " )
try :
try :
mm = ModuleManager ( client )
client = F5Client ( * * module . params )
mm = ModuleManager ( module = module , client = client )
results = mm . exec_module ( )
results = mm . exec_module ( )
cleanup_tokens ( client )
cleanup_tokens ( client )
client. module. exit_json ( * * results )
module. exit_json ( * * results )
except F5ModuleError as e :
except F5ModuleError as e x :
cleanup_tokens ( client )
cleanup_tokens ( client )
client. module. fail_json ( msg = str ( e ) )
module. fail_json ( msg = str ( e x ) )
if __name__ == ' __main__ ' :
if __name__ == ' __main__ ' :