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

相关推荐
梅孔立7 天前
Ansible 100 台服务器一键管控实战 进阶版
服务器·git·ansible
henry10101010 天前
Ansible自动化运维全攻略(AI生成)
linux·运维·python·ansible·devops
only_Klein13 天前
Ansible变量详解
运维·自动化·ansible
only_Klein13 天前
Ansible Roles 详解
自动化·ansible·role
only_Klein13 天前
Ansible 条件判断与流程控制详解
自动化·ansible
axPpcfNN14 天前
可直接编译运行 c#解析dxf可读取圆直线弧多段线源码-无封装缩放拖拽 可读取坐标信息 支持多...
ansible
Maggie_ssss_supp15 天前
Linux-ansible自动化运维
运维·自动化·ansible
迎仔15 天前
10-算力中心运维三剑客:Ansible + Jenkins + K8s 高效实战
运维·kubernetes·ansible·jenkins
识途老码17 天前
25.ansible的hostname模块
ansible·hostname
Cloud Traveler20 天前
Ansible+cpolar:NAS 远程自动化运维方案
ansible