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

相关推荐
User_芊芊君子4 天前
让异构增量同步飞起来-KFS全链路并行同步方案
运维·自动化·ansible
あ-6 天前
ansible-playbook安装seaweedfs三节点集群
ansible
Tassel_YUE8 天前
非 ansible 主机批量执行命令方法:psssh 和 pscp(随手记)
linux·网络·ssh·scp·ansible
亿朝亿夕17 天前
ansible安装
ansible
.柒宇.18 天前
运维常见面试题_07_配置管理与监控(Ansible · Prometheus · Alertmanager)· 容器编排(Kubernetes)
运维·k8s·ansible·prometheus
相顾若初见18 天前
Ansible部署k8s
容器·kubernetes·ansible
wzq11_66618 天前
ansible部署项目——基于tidb数据库安装zabbix_server
ansible·zabbix·tidb
吃不吃早饭19 天前
RHEL9 搭建 Harbor 私有仓库与 Ansible 自动化部署 Kubernetes 运行环境完整实践
kubernetes·自动化·ansible
wzq11_66619 天前
Ansible自动部署Redis——六步自动安装Redis数据库
ansible
mohesashou19 天前
红帽linux的K8S部署
linux·kubernetes·ansible