【发布时间】:2019-05-23 09:08:22
【问题描述】:
所以我试图从 Ansible 寄存器输出中获取特定的行/行。但由于我的输出是安静嵌套的,我似乎无法获得我想要的正确值。
Playbook 如下所示,
---
- name: Get some piece of information
*some Ansible module*:
epg_info: First_EPG
state: query
register: epg_info
- debug:
var: epg_info
...
所以你看我使用Ansible提供的一个网络模块来查询“First_EPG”的信息并在epg_info里面注册。接下来我调试它,这些是我得到的行,
ok: [... . ... . ... . ...] => {
"epg_info": {
"changed": false,
"msg": "All items completed",
"results": [
{
"_ansible_ignore_errors": null,
"changed": false,
"current": [
{
"fvAEPg": {
"attributes": {
"annotation": "",
"dn": "THIS IS THE LINE I WANT TO HAVE",
"exceptionTag": "",
"extMngdBy": "",
},
}
}
}
}
}
不要介意“{}”的数量,因为列表要长很多,我只是为了方便使用而缩小了范围。
如您所见,列表是安静嵌套的,我想要的唯一行是“dn”行,并将此值存储在另一个列表中。
有什么想法可以让我只得到那条线吗?
【问题讨论】:
标签: ansible yaml ansible-inventory ansible-facts