Ansible模板循环

问题描述

我正在尝试循环字典并设置变量。这就是我的模板文件中的内容

{% for item in db_server() %}
    {% if item.name in fqdn.stdout and item.MysqL == "MysqL-5-5-28" %}
        {% set version = "MysqL-5.5.28-linux2.6-x86_64" %}
    {% elif item.name in fqdn.stdout and item.MysqL == "MysqL-5-1-51" %}
        {% set version = "MysqL-5.1.51-linux-x86_64-glibc23" %}
    {% endif %}
{% endfor %}

我的var文件

db_server:
  - name: "test1"
    MysqL: "MysqL_5_5_28"
  - name: "test2"
    MysqL: "MysqL_5_5_28"
  - name: "test3"
    MysqL: "MysqL_5_5_28"

我遇到错误

fatal: [st-cms-db2]: Failed! => {
    "changed": false,"msg": "AttributeError: 'list' object has no attribute '__call__'"
}

我是ansible模板的新手。我是通过谷歌搜索写的。请客气...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)