• Ansible template中j2文件调用var中定义变量报错解决办法


    报错内容如下:

    fatal: [10.86.132.130]: FAILED! => {"changed": false, "msg": "AnsibleError: template error while templating string: expected token ':', got '}'. String: # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. dataDir={{ zookeeper_data_dir }} # the port at which the clients will connect clientPort=2181 # disable the per-ip limit on the number of connections since this is a non-production config maxClientCnxns=0 # Disable the adminserver by default to avoid port conflicts. # Set the port to something non-conflicting if choosing to enable this admin.enableServer=false # admin.serverPort=8080 #{% for zookeeper_cluster in zookeeper_cluster_server %} #server.{{ zookeeper_cluster.id }}={{ zookeeper_cluster.host }}:2888:3888 #{% endfor %} {% for server in groups[{{ group_name }}] %} server.{{ hostvars[server]['zookeeper_myid'] }}={{ hostvars[server]['inventory_hostname'] }}:2888:3888 {% endfor %} "}

    j2文件中配置如下:

    原因:
    j2文件中使用变量的时候,不需要 {{}},遇到if,for等条件判断语句,变量的话,只需要变量名即可,字符串需要 加上引号。

    解决办法:
    {% for server in groups[{{group_name}}] %}改为{% for server in groups[group_name] %}即可

  • 相关阅读:
    Linux常用操作命令
    Linux下查看CPU型号,内存大小,硬盘空间命令
    PhpExcel中文帮助手册|PhpExcel使用方法
    PHP操作cookie函数:setcookie()与setrawcookie()
    利用phantomjs模拟QQ自动登录
    无法在同一张表上查询和更新的问题解决方法
    App开放接口api安全性—Token签名sign的设计与实现
    开放api接口签名验证
    bootstrap字体图标
    booatrap中的表格样式
  • 原文地址:https://www.cnblogs.com/zhface/p/15457666.html
Copyright © 2020-2023  润新知