我已創建自定義的事實---> /etc/ansible/facts.d/hdfs.fact的產品清單(陣列)讀取自定義事實不能
當我跑步時用的劇本以下命令
- debug: var=ansible_local.hdfs
run_once: true
我得到預期如下回答:
PLAY [all] *********************************************************************
TASK [setup] *******************************************************************
ok: [cdh-2]
ok: [cdh-3]
ok: [cdh-1]
TASK [preparation : debug] *****************************************************
ok: [cdh-1] => {
"ansible_local.hdfs": {
"items": [
{
"base": true,
"config": {
"items": []
},
"displayName": "Failover Controller Default Group",
"name": "hdfs-FAILOVERCONTROLLER-BASE",
"roleType": "FAILOVERCONTROLLER",
"serviceRef": {
"clusterName": "cluster",
"serviceName": "hdfs"
}
},
{
"base": true,
"config": {
"items": [
{
"name": "balancer_java_heapsize",
"value": "491782144"
}
]
},
"displayName": "Balancer Default Group",
"name": "hdfs-BALANCER-BASE",
"roleType": "BALANCER",
"serviceRef": {
"clusterName": "cluster",
"serviceName": "hdfs"
}
},
{
"base": true,
"config": {
"items": []
},
"displayName": "HttpFS Default Group",
"name": "hdfs-HTTPFS-BASE",
"roleType": "HTTPFS",
"serviceRef": {
"clusterName": "cluster",
"serviceName": "hdfs"
}
}
]
}
}
我在如何可以解析來自JSON特定值的問題。 我已經試過很多語法沒有任何成功
debug: var=ansible_local.hdfs.items[0].config.displayName
debug: var=ansible_local.hdfs.items.config.displayName
hdfs.fact內容:
{
"items" : [ {
"name" : "hdfs-FAILOVERCONTROLLER-BASE",
"displayName" : "Failover Controller Default Group",
"roleType" : "FAILOVERCONTROLLER",
"base" : true,
"serviceRef" : {
"clusterName" : "cluster",
"serviceName" : "hdfs"
},
"config" : {
"items" : [ ]
}
}, {
"name" : "hdfs-BALANCER-BASE",
"displayName" : "Balancer Default Group",
"roleType" : "BALANCER",
"base" : true,
"serviceRef" : {
"clusterName" : "cluster",
"serviceName" : "hdfs"
},
"config" : {
"items" : [ {
"name" : "balancer_java_heapsize",
"value" : "491782144"
} ]
}
}, {
"name" : "hdfs-HTTPFS-BASE",
"displayName" : "HttpFS Default Group",
"roleType" : "HTTPFS",
"base" : true,
"serviceRef" : {
"clusterName" : "cluster",
"serviceName" : "hdfs"
},
"config" : {
"items" : [ ]
}
} ]
}
感謝
你能告訴我的輸出:ansible_local.hdfs.items – Shasha99