ansible问题排查

拷贝模板时报错:AnsibleError: template error while templating string: Missing end of comment tag.

原因

shell脚本中地{#和jinja中的语法comment tag相同,而且只有一半,导致无法渲染导致。

解决

在有语法冲突的地方使用组合标签{% raw %} 、{% endraw %}包裹起来,例如:

bash 复制代码
{% raw %}
    if [[ ${#info_array[*]} -ne 3 ]];then
        echo "ERROR:${info} Format Error,Please Excute:bash $0 -h" && exit 1
    fi
{% endraw %}

拷贝模板时报错:AnsibleError: template error while templating string: expected token ':', got '}'. String

错误的写法:

bash 复制代码
{% if {{ db_type}} == "mysql" %}
a=1
{% endif %}

正确的写法:

bash 复制代码
{% if db_type == "mysql" %}
a=1
{% endif %}

总结:在if,for等条件判断语句中变量不需加{{ }}

相关推荐
Warren986 小时前
复习MySQL
数据库·windows·tcp/ip·mysql·ubuntu·ssh·ansible
早睡冠军候选人3 天前
Ansible学习----Ansible Playbook
运维·服务器·学习·云原生·容器·ansible
yourkin6667 天前
Ansible
ansible
Ribou7 天前
ansible 自动安装软件,实现列表选择软件的方法
ansible
文静小土豆7 天前
Ansible 自动化部署K8S1.34.1
kubernetes·自动化·ansible
K_i1349 天前
Helm 与 Ansible 深度对比解析文档
自动化·ansible
zmjjdank1ng10 天前
什么是Ansible 清单
服务器·自动化·ansible
Yyyy48210 天前
ansible role配apt源
ansible
K_i13415 天前
Ansible实战:VMware下K8s自动化部署指南
kubernetes·自动化·ansible
许泽宇的技术分享16 天前
Ansible核心架构深度剖析:从源码看IT自动化的“简单“哲学
python·ansible·自动化运维·devops·it基础设施