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等条件判断语句中变量不需加{{ }}

相关推荐
聊天QQ:688238861 天前
光伏MPPT仿真:布谷鸟算法的奇妙结合
ansible
weixin_46682 天前
Ansible Playbook应用
网络·ansible
孪生质数-12 天前
Ansible基础入门
服务器·自动化·ansible·openstack
Empty_77712 天前
Ansible变量
服务器·github·ansible
哲Zheᗜe༘12 天前
学习Ansible Playbook 核心语法
网络·学习·ansible
凤凰战士芭比Q13 天前
Ansible剧本、变量、判断、循环
ansible
凤凰战士芭比Q13 天前
Ansible(安装、配置文件、命令行、常用模块)
linux·ansible
早睡冠军候选人16 天前
Ansible学习----管理复杂的 Play 和 Playbook 内容
运维·学习·云原生·ansible
雨奔16 天前
ansible使用教程
ansible
凡间客17 天前
Ansible安装与入门
linux·运维·ansible