我正在运行 if
bash 脚本中的语句。我需要在不同的服务器中部署 bash 脚本。下面是我的 if else 语句。
DIR="/backup/db"
first_time=true
{% if [ -d "$DIR" ]; then %}
first_time=false
sudo -u tomcat ln -s /backup/app /opt/tomcat/latest/webapps/msales
sudo -u tomcat ln -s /backup/store/logs /opt/tomcat/latest/logs
.....etc
{% fi %}
我正在使用 Ansible 将此 script.sh.j2 部署到另一台服务器。但它说""msg": "AnsibleError: template error while templating string: expected token ',', got 'string'."
如何在 j2 模板中使用 if 语句?
最佳答案
How to use if statements in j2 templates?
您应该read the docs .这是一个简单的例子:
{% if my_var == 1 %}
some text here with an actual variable: {{ my_other_var }}
{% else %}
some other text here with nothing
{% endif %}
关于bash - 如何在 Ansible Jinja2 (.j2) 模板中指定 "if else"语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66005654/