'Override post validation of vars on the play, as we don\'t want to
template these too early.'

def _post_validate_environment(self, attr, value, templar):

    env = {}
    if (value is not None):
        def _parse_env_kv(k, v):
            try:
                env[k] = templar.template(v, convert_bare=False)
            except AnsibleUndefinedVariable as e:
                if ((self.action in ('setup', 'gather_facts')) and ('ansible_env' in to_native(e))):
                    pass
        if isinstance(value, list):
            for env_item in value:
                if isinstance(env_item, dict):
                    for k in env_item:
                        _parse_env_kv(k, env_item[k])
                else:
                    isdict = templar.template(env_item, convert_bare=False)
                    if isinstance(isdict, dict):
                        env.update(isdict)
                    else:
                        display.warning(('could    not    parse    environment    value,    skipping:    %s' % value))
        elif isinstance(value, dict):
            env = dict()
            for env_item in value:
                _parse_env_kv(env_item, value[env_item])
        else:
            env = templar.template(value, convert_bare=False)
    return env
