# Buggy code
def get_api_client(self, **auth_params):
    auth_args = AUTH_ARG_SPEC.keys()

    auth_params = auth_params or getattr(self, "params", {})
    auth = copy.deepcopy(auth_params)

    configuration = kubernetes.client.Configuration()
    for key, value in iteritems(auth_params):
        if key in auth_args and value is not None:
            if key == "api_key":
                setattr(
                    configuration, key, {"authorization": "Bearer {0}".format(value)}
                )
            else:
                setattr(configuration, key, value)
        elif key in auth_args and value is None:
            env_value = os.getenv("K8S_AUTH_{0}".format(key.upper()), None)
            if env_value is not None:
                if key == "api_key":
                    setattr(
                        configuration,
                        key,
                        {"authorization": "Bearer {0}".format(env_value)},
                    )
                else:
                    setattr(configuration, key, env_value)
                    auth[key] = env_value

    kubernetes.client.Configuration.set_default(configuration)

    if auth.get("username") and auth.get("password") and auth.get("host"):
        auth_method = "params"
    elif auth.get("api_key") and auth.get("host"):
        auth_method = "params"
    elif auth.get("kubeconfig") or auth.get("context"):
        auth_method = "file"
    else:
        auth_method = "default"

    # First try to do incluster config, then kubeconfig
    if auth_method == "default":
        try:
            kubernetes.config.load_incluster_config()
            return DynamicClient(kubernetes.client.ApiClient())
        except kubernetes.config.ConfigException:
            return DynamicClient(
                self.client_from_kubeconfig(auth.get("kubeconfig"), auth.get("context"))
            )

    if auth_method == "file":
        return DynamicClient(
            self.client_from_kubeconfig(auth.get("kubeconfig"), auth.get("context"))
        )

    if auth_method == "params":
        return DynamicClient(kubernetes.client.ApiClient(configuration))


# Traceback (SSLError)
fatal: [k8s-deployment-host]: FAILED! => {
"changed": false,
"module_stderr": "2018-08-08 23:54:26,597 WARNING Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, u'[SSL: EXCESSIVE_MESSAGE_SIZE] excessive message size (_ssl.c:726)'),)': /version\n2018-08-08 23:54:26,597 WARNING Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, u'[SSL: EXCESSIVE_MESSAGE_SIZE] excessive message size (_ssl.c:726)'),)': /version\n2018-08-08 23:54:27,372 WARNING Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, u'[SSL: EXCESSIVE_MESSAGE_SIZE] excessive message size (_ssl.c:726)'),)': /version\n2018-08-08 23:54:27,372 WARNING Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, u'[SSL: EXCESSIVE_MESSAGE_SIZE] excessive message size (_ssl.c:726)'),)': /version\n2018-08-08 23:54:28,297 WARNING Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, u'[SSL: EXCESSIVE_MESSAGE_SIZE] excessive message size (_ssl.c:726)'),)': /version\n2018-08-08 23:54:28,297 WARNING Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, u'[SSL: EXCESSIVE_MESSAGE_SIZE] excessive message size (_ssl.c:726)'),)': /version\nTraceback (most recent call last):\n  File \"/var/folders/y9/f9hhc4r13mbdk6g9z2fqjxw40000gp/T/ansible_kcvrAN/ansible_module_k8s.py\", line 165, in <module>\n    main()\n  File \"/var/folders/y9/f9hhc4r13mbdk6g9z2fqjxw40000gp/T/ansible_kcvrAN/ansible_module_k8s.py\", line 161, in main\n    KubernetesRawModule().execute_module()\n  File \"/var/folders/y9/f9hhc4r13mbdk6g9z2fqjxw40000gp/T/ansible_kcvrAN/ansible_modlib.zip/ansible/module_utils/k8s/raw.py\", line 70, in execute_module\n  File \"/var/folders/y9/f9hhc4r13mbdk6g9z2fqjxw40000gp/T/ansible_kcvrAN/ansible_modlib.zip/ansible/module_utils/k8s/common.py\", line 164, in get_api_client\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/openshift/dynamic/client.py\", line 58, in __init__\n    self._load_server_info()\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/openshift/dynamic/client.py\", line 62, in _load_server_info\n    self.__version = {'kubernetes': load_json(self.request('get', '/version'))}\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/openshift/dynamic/client.py\", line 255, in request\n    _return_http_data_only=params.get('_return_http_data_only', True)\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/kubernetes/client/api_client.py\", line 321, in call_api\n    _return_http_data_only, collection_formats, _preload_content, _request_timeout)\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/kubernetes/client/api_client.py\", line 155, in __call_api\n    _request_timeout=_request_timeout)\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/kubernetes/client/api_client.py\", line 342, in request\n    headers=headers)\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/kubernetes/client/rest.py\", line 231, in GET\n    query_params=query_params)\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/kubernetes/client/rest.py\", line 205, in request\n    headers=headers)\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/urllib3/request.py\", line 68, in request\n    **urlopen_kw)\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/urllib3/request.py\", line 89, in request_encode_url\n    return self.urlopen(method, url, **extra_kw)\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/urllib3/poolmanager.py\", line 322, in urlopen\n    response = conn.urlopen(method, u.request_uri, **kw)\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/urllib3/connectionpool.py\", line 667, in urlopen\n    **response_kw)\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/urllib3/connectionpool.py\", line 667, in urlopen\n    **response_kw)\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/urllib3/connectionpool.py\", line 667, in urlopen\n    **response_kw)\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/urllib3/connectionpool.py\", line 638, in urlopen\n    _stacktrace=sys.exc_info()[2])\n  File \"/usr/local/Cellar/ansible/2.6.2/libexec/lib/python2.7/site-packages/urllib3/util/retry.py\", line 398, in increment\n    raise MaxRetryError(_pool, url, error or ResponseError(cause))\nurllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='k8s.aureacentral.com', port=6443): Max retries exceeded with url: /version (Caused by SSLError(SSLError(1, u'[SSL: EXCESSIVE_MESSAGE_SIZE] excessive message size (_ssl.c:726)'),))\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}

# Fixed code
def get_api_client(self, **auth_params):
    auth_args = AUTH_ARG_SPEC.keys()

    auth_params = auth_params or getattr(self, "params", {})
    auth = copy.deepcopy(auth_params)

    # If authorization variables aren't defined, look for them in environment variables
    for key, value in iteritems(auth_params):
        if key in auth_args and value is None:
            env_value = os.getenv("K8S_AUTH_{0}".format(key.upper()), None)
            if env_value is not None:
                auth[key] = env_value

    def auth_set(*names):
        return all([auth.get(name) for name in names])

    if auth_set("username", "password", "host") or auth_set("api_key", "host"):
        # We have enough in the parameters to authenticate, no need to load incluster or kubeconfig
        pass
    elif auth_set("kubeconfig", "context"):
        kubernetes.config.load_kube_config(auth.get("kubeconfig"), auth.get("context"))
    else:
        # First try to do incluster config, then kubeconfig
        try:
            kubernetes.config.load_incluster_config()
        except kubernetes.config.ConfigException:
            kubernetes.config.load_kube_config(
                auth.get("kubeconfig"), auth.get("context")
            )

    # Override any values in the default configuration with Ansible parameters
    configuration = kubernetes.client.Configuration()
    for key, value in iteritems(auth):
        if key in auth_args and value is not None:
            if key == "api_key":
                setattr(
                    configuration, key, {"authorization": "Bearer {0}".format(value)}
                )
            else:
                setattr(configuration, key, value)

    kubernetes.client.Configuration.set_default(configuration)
    return DynamicClient(kubernetes.client.ApiClient(configuration))