Ansible - 如何使用 ansible_fact 深度嵌入?
Ansible - How do I use an ansible_fact deeply embedded?
我似乎无法使用以下字符串访问深度嵌入的 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"?
谢谢!
这是一个列表,使用所需字段的索引:
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'
我似乎无法使用以下字符串访问深度嵌入的 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"? 谢谢!
这是一个列表,使用所需字段的索引:
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'