You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

仅修改vars.yml条件实现Jinja2模板listener参数按规则生成

实现方案

1. 调整test.j2模板内容

原模板写死了固定的协议后缀与端口,无法适配多协议多端口的输出需求,调整为直接引用完整的protocol变量值即可:

listener={{ protocol }}

2. 修改vars.yml中protocol的条件逻辑

完全基于要求的三个场景调整Jinja2判断规则,同时添加空白控制符避免生成多余的空格/换行:

---
sasl:
  enabled: true
  realm:
    admin_server: test.dev.com
ssl:
  enabled: true
  pwd: PASS
protocol: >-
  {%- if sasl.enabled and ssl.enabled -%}
  sasl_ssl://localhost:9094,ssl://localhost:9093
  {%- elif ssl.enabled and not sasl.enabled -%}
  ssl://localhost:9093
  {%- else -%}
  PLAIN_TEXT://localhost:9094
  {%- endif -%}

效果验证

修改sasl.enabled和ssl.enabled的取值即可测试所有场景:

  • 两者均为true:输出listener=sasl_ssl://localhost:9094,ssl://localhost:9093
  • 仅ssl.enabled为true:输出listener=ssl://localhost:9093
  • 其他所有场景:输出listener=PLAIN_TEXT://localhost:9094

内容的提问来源于stack exchange,提问作者hruday

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 09:06:01