0

我似乎无法使用此字符串访问深度嵌入的 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”?谢谢!

4

1 回答 1

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'
于 2017-11-26T20:58:55.900 回答