'run idempotent ansible code'

@staticmethod
def run_ansible(params, check_mode):

    registry_options = {'images': {'value': params['images'], 'include': True}, 'latest_images': {'value': params['latest_images'], 'include': True}, 'labels': {'value': params['labels'], 'include': True}, 'ports': {'value': ','.join(params['ports']), 'include': True}, 'replicas': {'value': params['replicas'], 'include': True}, 'selector': {'value': params['selector'], 'include': True}, 'service_account': {'value': params['service_account'], 'include': True}, 'mount_host': {'value': params['mount_host'], 'include': True}, 'env_vars': {'value': params['env_vars'], 'include': False}, 'volume_mounts': {'value': params['volume_mounts'], 'include': False}, 'edits': {'value': params['edits'], 'include': False}, 'tls_key': {'value': params['tls_key'], 'include': True}, 'tls_certificate': {'value': params['tls_certificate'], 'include': True}}
    if params['daemonset']:
        registry_options['daemonset'] = {'value': params['daemonset'], 'include': True}
    if params['enforce_quota']:
        registry_options['enforce_quota'] = {'value': params['enforce_quota'], 'include': True}
    rconfig = RegistryConfig(params['name'], params['namespace'], params['kubeconfig'], registry_options)
    ocregistry = Registry(rconfig, params['debug'])
    api_rval = ocregistry.get()
    state = params['state']
    if (state == 'list'):
        if (api_rval['returncode'] != 0):
            return {'failed': True, 'msg': api_rval}
        return {'changed': False, 'results': api_rval, 'state': state}
    if (state == 'absent'):
        if (not ocregistry.exists()):
            return {'changed': False, 'state': state}
        if check_mode:
            return {'changed': True, 'msg': 'CHECK_MODE:    Would    have    performed    a    delete.'}
        api_rval = ocregistry.delete()
        if (api_rval['returncode'] != 0):
            return {'failed': True, 'msg': api_rval}
        return {'changed': True, 'results': api_rval, 'state': state}
    if (state == 'present'):
        if (not ocregistry.exists()):
            if check_mode:
                return {'changed': True, 'msg': 'CHECK_MODE:    Would    have    performed    a    create.'}
            api_rval = ocregistry.create()
            if (api_rval['returncode'] != 0):
                return {'failed': True, 'msg': api_rval}
            return {'changed': True, 'results': api_rval, 'state': state}
        if ((not params['force']) and (not ocregistry.needs_update())):
            return {'changed': False, 'state': state}
        if check_mode:
            return {'changed': True, 'msg': 'CHECK_MODE:    Would    have    performed    an    update.'}
        api_rval = ocregistry.update()
        if (api_rval['returncode'] != 0):
            return {'failed': True, 'msg': api_rval}
        return {'changed': True, 'results': api_rval, 'state': state}
    return {'failed': True, 'msg': ('Unknown    state    passed.    %s' % state)}
