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

相关推荐
祺风挽楠6 天前
ansible编辑
网络·ansible
芳心粽伙饭7 天前
Ansible课后作业
ansible
烁3478 天前
Ansible初识
ansible
烁3478 天前
Ansible安装部署调试
ansible
烁3478 天前
Ansible命令
ansible
小义_8 天前
【Ansible】(三)基础配置与连接设置
云原生·ansible
炸炸鱼.13 天前
Ansible 企业级实战:Playbook 与 Roles 完全指南
网络·ansible
风曦Kisaki13 天前
# 自动化运维Day03:Ansible模块进阶(setup,debug),四种常用变量,进阶语法;Ansible Roles(角色)
运维·自动化·ansible
炸炸鱼.16 天前
Ansible 部署应用:从入门到精通
ansible
Peace16 天前
【Ansible】
linux·运维·ansible