当Ansible收集有关主机的事实时,例如获取主机的所有坐骑:
"ansible_mounts": [
{
"block_available": 7800291,
"block_size": 4096,
"block_total": 8225358,
"block_used": 425067,
"device": "/dev/mapper/foobar",
"fstype": "xfs",
"inode_available": 16403366,
"inode_total": 16458752,
"inode_used": 55386,
"mount": "/",
"options": "rw,seclabel,relatime,attr2,inode64,noquota",
"size_available": 31949991936,
"size_total": 33691066368,
"uuid": "2ebc82cb-5bc2-4db9-9914-33d65ba350b8"
},
{
"block_available": 44648,
"block_size": 4096,
"block_total": 127145,
"block_used": 82497,
"device": "/dev/sda1",
"fstype": "xfs",
"inode_available": 255595,
"inode_total": 256000,
"inode_used": 405,
"mount": "/boot",
"options": "rw,seclabel,relatime,attr2,inode64,noquota",
"size_available": 182878208,
"size_total": 520785920,
"uuid": "c5f7eaf2-5b70-4f74-8189-a63bb4bee5f8"
},
等等。因此,我想做的是:在模板中,我想遍历数组中的所有对象,并输出每个“ mount”键的值。
我这样尝试:
(% for mounts in {{ ansible_mounts }} %)
Mountpoint: {{ ansible_mounts.mount }}
(% endfor %)
但这是行不通的。我尝试了其他类似iteritems()的东西,但无法正常工作。据我所知,Ansible的输出在json中,如果有帮助的话。有人知道解决方案,还是更多关于stackoverflow的问题?
感谢您的回答。