'run the idempotent ansible code'

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

    gconfig = GroupConfig(params['name'], params['namespace'], params['kubeconfig'])
    oc_group = OCGroup(gconfig, verbose=params['debug'])
    state = params['state']
    api_rval = oc_group.get()
    if (api_rval['returncode'] != 0):
        return {'failed': True, 'msg': api_rval}
    if (state == 'list'):
        return {'changed': False, 'results': api_rval['results'], 'state': state}
    if (state == 'absent'):
        if oc_group.exists():
            if check_mode:
                return {'changed': True, 'msg': 'CHECK_MODE:    Would    have    performed    a    delete.'}
            api_rval = oc_group.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_group.exists()):
            if check_mode:
                return {'changed': True, 'msg': 'CHECK_MODE:    Would    have    performed    a    create.'}
            api_rval = oc_group.create()
            if (api_rval['returncode'] != 0):
                return {'failed': True, 'msg': api_rval}
            api_rval = oc_group.get()
            if (api_rval['returncode'] != 0):
                return {'failed': True, 'msg': api_rval}
            return {'changed': True, 'results': api_rval, 'state': state}
        if oc_group.needs_update():
            api_rval = oc_group.update()
            if (api_rval['returncode'] != 0):
                return {'failed': True, 'msg': api_rval}
            api_rval = oc_group.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, 'msg': 'Unknown    state    passed.    {}'.format(state)}
