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

相关推荐
杨了个杨89829 小时前
Ansible的常见用法
ansible
陈桴浮海12 小时前
【Linux&Ansible】学习笔记合集三
linux·运维·云原生·ansible
Sheffield1 天前
command和shell模块到底区别在哪?
linux·云计算·ansible
陈桴浮海1 天前
【Linux&Ansible】学习笔记合集二
linux·学习·ansible
馨谙2 天前
Ansible模块化Playbook管理:静态导入与动态包含详解
运维·ansible
馨谙3 天前
Ansible 事实(Facts)全面指南:自动化运维中的主机信息管理
运维·ansible
馨谙3 天前
Ansible处理程序完全指南:实现智能的任务触发机制
运维·ansible
馨谙3 天前
Ansible 多 Play 编写与模块使用全解析
运维·ansible
馨谙4 天前
Ansible 清单详解:静态清单的构建与管理
ansible
馨谙4 天前
Ansible 配置文件详解:让自动化管理更轻松
运维·github·ansible