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

相关推荐
道清茗1 天前
【RH294知识点汇总】第 7 章 《 使用角色和 Ansible 内容集合简化 Playbook 》常见问题
ansible
何中应3 天前
Ansible安装&使用
运维·自动化·ansible·运维开发·自动化运维
王九思3 天前
Ansible 自动化运维基础—模板
运维·自动化·ansible
道清茗4 天前
【RH294知识点汇总】第 7 章 《 使用角色和 Ansible 内容集合简化 Playbook 》
java·前端·ansible
切糕师学AI4 天前
深入解析 Ansible:从入门到实践
ansible
王的宝库4 天前
【Ansible】变量与敏感数据管理:Vault 加密 + Facts 采集详解
笔记·学习·ansible
张3235 天前
Ansible拆分大型Playbook
linux·ansible
爱莉希雅&&&6 天前
Ansible+Docker案例(含ansible配置安装docker)
linux·运维·mysql·nginx·docker·容器·ansible
张3236 天前
配置加载混淆(vars_files与from_yaml)
ansible
张3236 天前
角色与内容集合:自动化配置的标准化复用机制
运维·自动化·ansible