'run the idempotent ansible code'

@staticmethod
def run_ansible(params, check_mode):

    state = params['state']
    action = None
    if (state == 'present'):
        action = (('add-' + params['resource_kind']) + '-to-group')
    else:
        action = (('remove-' + params['resource_kind']) + '-from-group')
    nconfig = PolicyGroupConfig(params['namespace'], params['kubeconfig'], {'action': {'value': action, 'include': False}, 'group': {'value': params['group'], 'include': False}, 'resource_kind': {'value': params['resource_kind'], 'include': False}, 'name': {'value': params['resource_name'], 'include': False}})
    policygroup = PolicyGroup(nconfig, params['debug'])
    if (state == 'absent'):
        if (not policygroup.exists()):
            return {'changed': False, 'state': 'absent'}
        if check_mode:
            return {'changed': False, 'msg': 'CHECK_MODE:    would    have    performed    a    delete.'}
        api_rval = policygroup.perform()
        if (api_rval['returncode'] != 0):
            return {'msg': api_rval}
        return {'changed': True, 'results': api_rval, state: 'absent'}
    if (state == 'present'):
        results = policygroup.exists()
        if (isinstance(results, dict) and ('returncode' in results) and (results['returncode'] != 0)):
            return {'msg': results}
        if (not results):
            if check_mode:
                return {'changed': False, 'msg': 'CHECK_MODE:    would    have    performed    a    create.'}
            api_rval = policygroup.perform()
            if (api_rval['returncode'] != 0):
                return {'msg': api_rval}
            return {'changed': True, 'results': api_rval, state: 'present'}
        return {'changed': False, state: 'present'}
    return {'failed': True, 'changed': False, 'results': ('Unknown    state    passed.    %s' % state), state: 'unknown'}
