我似乎无法使用此字符串访问深度嵌入的ansible_fact:
hostvars[inventory_hostname]['ansible_devices']['sda']['partitions']['sda2']['holders'] }}
这是我尝试引用的事实树的一部分。
"ansible_devices": {
"sda": {
"holders": [],
"host": "RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS-3 3108 [Invader] (rev 02)",
"partitions": {
"sda1": {
"holders": [],
"sectors": "614400",
"sectorsize": 512,
"size": "300.00 MB",
"start": "2048",
},
"sda2": {
"holders": [
"root-root",
"root-swap",
"root-home",
"root-opt",
"root-tmpl",
"root-usr",
"root-var"
],
我将如何检查分区" root-home"? 谢谢!
答案 0 :(得分:0)
这是一个列表,使用有用字段的索引:
hostvars[inventory_hostname]['ansible_devices']['sda']['partitions']['sda2']['holders'][2]
或
hostvars.inventory_hostname.ansible_devices.sda.partitions.sda2.holders[2]
我建议尝试 jq 命令:
ansible -m setup -l your_hostgroup | sed '1c {' | jq '.|keyes'