'run the idempotent ansible code'

@staticmethod
def run_ansible(params, check_mode):

    oc_clusterrole = OCClusterRole(params['name'], params['rules'], params['kubeconfig'], params['debug'])
    state = params['state']
    api_rval = oc_clusterrole.get()
    if (state == 'list'):
        return {'changed': False, 'results': api_rval, 'state': state}
    if (state == 'absent'):
        if oc_clusterrole.exists():
            if check_mode:
                return {'changed': True, 'msg': 'CHECK_MODE:    Would    have    performed    a    delete.'}
            api_rval = oc_clusterrole.delete()
            if (api_rval['returncode'] != 0):
                return {'failed': True, 'msg': api_rval}
            return {'changed': True, 'results': api_rval, 'state': state}
        return {'changed': False, 'state': state}
    if (state == 'present'):
        if (not oc_clusterrole.exists()):
            if check_mode:
                return {'changed': True, 'msg': 'CHECK_MODE:    Would    have    performed    a    create.'}
            api_rval = oc_clusterrole.create()
            if (api_rval['returncode'] != 0):
                return {'failed': True, 'msg': api_rval}
            api_rval = oc_clusterrole.get()
            if (api_rval['returncode'] != 0):
                return {'failed': True, 'msg': api_rval}
            return {'changed': True, 'results': api_rval, 'state': state}
        if oc_clusterrole.needs_update():
            if check_mode:
                return {'changed': True, 'msg': 'CHECK_MODE:    Would    have    performed    an    update.'}
            api_rval = oc_clusterrole.update()
            if (api_rval['returncode'] != 0):
                return {'failed': True, 'msg': api_rval}
            api_rval = oc_clusterrole.get()
            if (api_rval['returncode'] != 0):
                return {'failed': True, 'msg': api_rval}
            return {'changed': True, 'results': api_rval, 'state': state}
        return {'changed': False, 'results': api_rval, 'state': state}
    return {'failed': True, 'changed': False, 'msg': ('Unknown    state    passed.    [%s]' % state)}
