'perform the ansible idempotent code'

@staticmethod
def run_ansible(params, check_mode=False):

    ocobj = OCObject(params['kind'], params['namespace'], params['name'], params['selector'], kubeconfig=params['kubeconfig'], verbose=params['debug'], all_namespaces=params['all_namespaces'])
    state = params['state']
    api_rval = ocobj.get()
    if (state == 'list'):
        return {'changed': False, 'results': api_rval, 'state': state}
    if (state == 'absent'):
        if (((params['name'] is not None) or (params['selector'] is not None)) and ((len(api_rval['results']) == 0) or (('items' in api_rval['results'][0]) and (len(api_rval['results'][0]['items']) == 0)))):
            return {'changed': False, 'state': state}
        if check_mode:
            return {'changed': True, 'msg': 'CHECK_MODE:    Would    have    performed    a    delete'}
        api_rval = ocobj.delete()
        if (api_rval['returncode'] != 0):
            return {'failed': True, 'msg': api_rval}
        return {'changed': True, 'results': api_rval, 'state': state}
    if (not params['name']):
        return {'failed': True, 'msg': 'Please    specify    a    name    when    state    is    present.'}
    if (state == 'present'):
        if (not Utils.exists(api_rval['results'], params['name'])):
            if check_mode:
                return {'changed': True, 'msg': 'CHECK_MODE:    Would    have    performed    a    create'}
            api_rval = ocobj.create(params['files'], params['content'])
            if (api_rval['returncode'] != 0):
                return {'failed': True, 'msg': api_rval}
            api_rval = ocobj.get()
            if (api_rval['returncode'] != 0):
                return {'failed': True, 'msg': api_rval}
            if (params['files'] and params['delete_after']):
                Utils.cleanup(params['files'])
            return {'changed': True, 'results': api_rval, 'state': state}
        update = ocobj.needs_update(params['files'], params['content'])
        if (not isinstance(update, bool)):
            return {'failed': True, 'msg': update}
        if (not update):
            if (params['files'] and params['delete_after']):
                Utils.cleanup(params['files'])
            return {'changed': False, 'results': api_rval['results'][0], 'state': state}
        if check_mode:
            return {'changed': True, 'msg': 'CHECK_MODE:    Would    have    performed    an    update.'}
        api_rval = ocobj.update(params['files'], params['content'], params['force'])
        if (api_rval['returncode'] != 0):
            return {'failed': True, 'msg': api_rval}
        api_rval = ocobj.get()
        if (api_rval['returncode'] != 0):
            return {'failed': True, 'msg': api_rval}
        return {'changed': True, 'results': api_rval, 'state': state}
