【发布时间】:2020-06-02 05:19:12
【问题描述】:
我正在为 Docker 处理 ansible example。
我需要像示例中一样发布一个端口,但使用 if 语句 if port else omit。像这样:
docker_container:
name: myapplication
...
ports:
- "{{ if port else omit }}" # the {{ port }} variable is set from the default task.
...
但每次我运行它时,Docker 守护进程都会告诉我:
template error while templating string: expected token 'end of print statement', got 'port'. String: {{ if port else omit }}"
如果变量{{ port }}为空,如何省略设置端口?
提前感谢您的帮助。
【问题讨论】:
-
你应该接受一个答案,如果它解决了你的问题,我认为 β.εηοιτ.βε 答案可以解决