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

相关推荐
鲸屿19516 分钟前
Ansible之playbook
服务器·网络·ansible
Sweety丶╮79416 小时前
【Ansible】的介绍
云原生·ansible
知白守黑26716 小时前
Ansible角色
运维·服务器·ansible
Sweety丶╮7941 天前
【Ansible】实施 Ansible Playbook知识点
服务器·云原生·ansible
YC运维2 天前
Ansible题目全解析与答案
java·算法·ansible
--运维实习生--3 天前
自动化运维之ansible
运维·自动化·ansible
神秘人X7074 天前
Ansible 角色使用指南
ansible·角色
维尔切4 天前
自动化运维-ansible中对于大项目的管理
运维·自动化·ansible
Gss7774 天前
ansible变量+管理机密
linux·运维·ansible
误入运维泥潭4 天前
Ansible自动化运维:从入门到精通
linux·ansible·module