gpt4 book ai didi

ansible - 无法使用项目列表(数组)读取自定义事实

转载 作者:行者123 更新时间:2023-12-01 09:49:48 28 4
gpt4 key购买 nike

我创建了自定义事实 --->/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" : [ ]
}
} ]
}

谢谢

最佳答案

原因debug: var=ansible_local.hdfs.items.config.displayName失败是items是保留字。

尝试
debug: var=ansible_local.hdfs['items'].config.displayName反而。

我在来自 的帖子中找到了解决方案拉扎特拉维察 这里
https://github.com/ansible/ansible/issues/10581

关于ansible - 无法使用项目列表(数组)读取自定义事实,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40281706/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com