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

相关推荐
秋4279 小时前
ansible配置与模块介绍
ansible
秋42717 小时前
ansible剧本
linux·服务器·ansible
码农101号2 天前
Ansible - Role介绍 和 使用playbook部署wordPress
android·ansible
2301_800050993 天前
Ansible
运维·ansible
阎*水5 天前
Ansible 核心要点总结
ansible
小安运维日记6 天前
RHCA - DO374 | Day09:自定义内容集和执行环境
linux·运维·服务器·系统架构·ansible·改行学it
-dcr6 天前
48.Ansible自动化
自动化·ansible·dubbo
神秘面具男036 天前
Ansible Playbook 编写与运行
服务器·网络·ansible
随风语6 天前
ansible
运维·自动化·ansible
tianyuanwo6 天前
纵深防御:构建安全高效的 Ansible 自动化运维体系
运维·安全·ansible