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

相关推荐
遇见火星12 天前
如何使用Ansible一键部署MinIO集群?
ansible
粥周粥12 天前
ANSIBLE
ansible
码农101号12 天前
Linux中ansible模块补充和playbook讲解
linux·运维·ansible
码农101号12 天前
Linux的Ansible软件基础使用讲解和ssh远程连接
ansible
烟雨书信13 天前
ANSIBLE运维自动化管理端部署
运维·自动化·ansible
碎碎-li13 天前
ANSIBLE(运维自动化)
运维·自动化·ansible
@donshu@17 天前
Linux运维-ansible-python开发-获取inventroy信息
linux·运维·ansible
Kendra91920 天前
Ansible
ansible
꧁༺朝花夕逝༻꧂23 天前
Ansible小试牛刀
ansible
꧁༺朝花夕逝༻꧂23 天前
Ansible+Zabbix-agent2快速实现对多主机监控
运维·ansible