【发布时间】:2020-02-28 00:02:09
【问题描述】:
我有一个 JSON 数组,如下所示:
[
{
"item": {
"item": "SERVERNAME"
}
},
{
"item": {
"item": "SERVERNAME2"
}
}
]
在我之前使用的 API 调用中
with_items: "{{ cluster_server.results }}"
并且能够通过 {{ item.item.item }}
获取每个服务器名称但是在这个 API 调用上我只需要第一个结果,所以使用
with_items: "{{ cluster_server.results | first}}"
但它返回此错误:
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'item'\n\nThe error appears to be in '/home/mycomp/Documents/ansible/build-auth.yml': line 177, column 6, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - copy:\n ^ here\n"}
我在这里做错了什么?对 Ansible 来说相当陌生。
【问题讨论】: