@ -18,7 +18,8 @@
from __future__ import absolute_import , division , print_function
import copy
from ansible . module_utils . k8s . common import AUTH_ARG_SPEC , COMMON_ARG_SPEC
from ansible . module_utils . six import string_types
from ansible . module_utils . k8s . common import KubernetesAnsibleModule
from ansible . module_utils . common . dict_transformations import dict_merge
@ -34,6 +35,13 @@ except ImportError:
class KubernetesRawModule ( KubernetesAnsibleModule ) :
@property
def argspec ( self ) :
argument_spec = copy . deepcopy ( COMMON_ARG_SPEC )
argument_spec . update ( copy . deepcopy ( AUTH_ARG_SPEC ) )
argument_spec [ ' merge_type ' ] = dict ( choices = [ ' json ' , ' merge ' , ' strategic-merge ' ] )
return argument_spec
def __init__ ( self , * args , * * kwargs ) :
self . client = None
@ -203,7 +211,15 @@ class KubernetesRawModule(KubernetesAnsibleModule):
k8s_obj = dict_merge ( existing . to_dict ( ) , definition )
else :
try :
k8s_obj = resource . patch ( definition , name = name , namespace = namespace ) . to_dict ( )
params = dict ( name = name , namespace = namespace )
if self . params [ ' merge_type ' ] :
from distutils . version import LooseVersion
if LooseVersion ( self . openshift_version ) < LooseVersion ( " 0.6.2 " ) :
self . fail_json ( msg = " openshift >= 0.6.2 is required for merge_type " )
params [ ' content_type ' ] = ' application/ {0} -patch+json ' . format ( self . params [ ' merge_type ' ] )
k8s_obj = resource . patch ( definition , * * params ) . to_dict ( )
match , diffs = self . diff_objects ( existing . to_dict ( ) , k8s_obj )
result [ ' result ' ] = k8s_obj
except DynamicApiError as exc :
self . fail_json ( msg = " Failed to patch object: {0} " . format ( exc . body ) ,
error = exc . status , status = exc . status , reason = exc . reason )