ansible - hostvars 'list object' 没有属性
问题描述
我试图从 hostvars 获得一些结果,但失败了。
剧本:
- debug:
msg: "{{hostvars[item]['a']}}"
run_once: true
delegate_to: localhost
with_items: "{{ groups['all'] }}"
结果:
ok: [ansible8] => (item=ansible8) => {
"msg": [
{
"ansible_job_id": "921062922128.33800",
"attempts": 1,
"end": "2021-09-16 05:39:47.335977",
blah blah
"start": "2021-09-16 05:39:46.323621"
}
]
}
ok: [ansible8] => (item=ansible7) => {
"msg": [
{
"ansible_job_id": "688007320452.57867",
"attempts": 1,
"end": "2021-04-03 22:12:40.249637",
blah blah
"start": "2021-04-03 22:12:39.241665"
}
]
}
现在,我想得到 a.start 和 a.end,所以我的剧本是这样的:
- debug:
msg: "{{hostvars[item]['a']['start']}}"
run_once: true
delegate_to: localhost
with_items: "{{ groups['all'] }}"
但显然它没有用,并得到错误消息
“该任务包括一个带有未定义变量的选项。错误是:'列表对象'没有属性'开始'
感谢任何帮助,谢谢
解决方案
推荐阅读
- mysql - 如何提高静态网站的 WordPress GraphQL 服务器的效率
- python - 使用 keras 进行情绪分析,包括中性推文
- linux - linux中系统调用和内核线程的区别以及它们之间的关系
- javascript - 使用 Jquery AJAX 将数据发布到 JSON 数组中
- java - 无法匹配 PHP 和 JAVA 中的加密有效负载字符串响应
- javascript - HTMLCollection 索引更改未反映在 .append() 之后的变量中
- c++ - 该程序不会读取整个文件
- c++ - 这一步背后的直觉?
- database - 在 postgreSQL 中查询数据时出错
- c - 当我们改变指针的内容时,指针指向哪里?