我正在尝试从寄存器输出result.containers填充字典,恰巧会覆盖具有相同值的item.Image。 这是我的输出。
"result.containers": [
{
"Image": "lna-docker/webproxy:2.4.0",
"Names": [
"/se-webproxyui-dev-01"
],
},
{
"Image": "lna-docker-dev-local/webproxy:1.8.1",
"Names": [
"/se-webproxy-dev-01"
],
},
{
"Image": "docker-release/consul:1.0.1",
"Names": [
"/consul-client"
],
},
{
"Image": "docker.dev/webproxy:0.6.1",
"Names": [
"/webproxy-dev-01"
],
},
]
}
这是我的代码。
- name: Populate dictonary for containerup
set_fact:
containeruplist: "{{ containeruplist|default({}) | combine({item.Image.split('/')[-1].split(':')[0]:item.Names[0][1:]} ) }}"
loop: "{{ result.containers }}"
这是我的输出
ok: [VM3node.lite.com] => {
"containeruplist": {
"consul": "consul-client",
"webproxy": "webproxy-dev-01"
}
}
我正在尝试从寄存器输出result.containers
填充字典,该输出恰巧会覆盖具有相同值的item.Image。任何帮助将不胜感激。
理想情况下,我应该低于输出。它覆盖了前两个item.Image,其值为“ webroxy”。有人可以帮助我实现以下目标吗?
containeruplist": {
"webproxy":"se-webproxyui-dev-01"
"webproxy":"se-webproxy-dev-01"
"consul": "consul-client",
"webproxy": "webproxy-dev-01"
}