AnsibleError: template error while templating string: expected token ':', got

AnsibleError: template error while templating string: expected token ':', got

我有以下 JSON 文件。

[
  {
    "NODE": "ha2(VRM02)",
    "ROLE": "active",
    "PHASE": "Actived",
    "RESS": "normal",
  },
  {
    "NODE": "ha1(VRM01)",
    "ROLE": "standby",
    "PHASE": "Deactived",
    "RESS": "normal",
  }
]

通过 ansible,我将它存储在一个名为“fusionquery1”的变量中。 通过一个模板,我试图通过它来创建一个包含 JSON 文件中的一些数据的文件。到目前为止,我没有收到错误。

{% for item in fusionquery1 %}
{% set item = fusionquery1[loop.index-1] %}
{{item.NODE}},NODE ROLE,NA,OK,cualitativo,igualA,ROLE,{{item.ROLE}}
{% endfor %}

我的问题是当我想将此条件添加到上述语句的一侧时

{% if ({{item.NODE}} == "ha2(VRM02)" and {{item.ROLE}} == "active") or ({{item.NODE}} == "ha1(VRM01)" and {{item.ROLE}} == "standby") %}Ok{% else %}Failed{% endif %}

我收到以下错误

FAILED! => {"changed": false, "msg": "AnsibleError: template error while templating string: expected token ':', got '}'. String: {% for item in fusionquery1 %}\r\n{% set item = fusionquery1[loop.index-1] %}\r\n{{item.NODE}},NODE ROLE,NA,OK,cualitativo,igualA,ROLE,{{item.ROLE}},{% if ({{item.NODE}} == \"ha2(VRM02)\" and {{item.ROLE}} == \"active\") or ({{item.NODE}} == \"ha1(VRM01)\" and {{item.ROLE}} == \"standby\") %}Ok{% else %}Failed{% endif %}\r\n{% endfor %}\r\n"}

去掉条件中的大括号,例如

    - debug:
        msg: |
          {% for item in fusionquery1 %}
          {% if (item.NODE == "ha2(VRM02)" and item.ROLE == "active") or
                (item.NODE == "ha1(VRM01)" and item.ROLE == "standby") %}
          Ok
          {% else %}
          Failed
          {% endif %}
          {% endfor %}

给予

  msg: |-
    Ok
    Ok