从ansible中的列表创建字典
我有以下结果,我想创建字典表单列表。你能给我个建议吗 输入:从ansible中的列表创建字典,ansible,Ansible,我有以下结果,我想创建字典表单列表。你能给我个建议吗 输入: "destination": [ [ "URL=http://apps.introext.net/meta.html,checksum=99e2714f6269cbe49fe641ab9f4f84e661334fa4,remotefile=meta.html" ], [ "URL=http://apps.introext.net/data.html,checksum=7985
"destination": [
[
"URL=http://apps.introext.net/meta.html,checksum=99e2714f6269cbe49fe641ab9f4f84e661334fa4,remotefile=meta.html"
],
[
"URL=http://apps.introext.net/data.html,checksum=7985e6b97a915ec6681b628c783fa2a52c6f055a,remotefile=data.html"
]
]
}
预期产出:
{"URL":"http://apps.introext.net/meta.html", "checksum":"99e2714f6269cbe49fe641ab9f4f84e661334fa2","remotefile":"meta.html"}
{"URL":"http://apps.introext.net/data.html","checksum":"7985e6b97a915ec6681b628c788522a52c6f055a","remotefile":"data.html"}
谢谢,
麦迪好吧,这就是它的作用。试着做下面的事情,然后阅读我发送的链接中的所有帖子。。。它会根据你的需要工作
tasks:
- set_fact:
first_list: "{{ first_list | default([]) + [item.split(',')] }}"
with_items: "{{ destination }}"
- set_fact:
final_list: "{{ final_list | default([]) | combine(dict([ item.partition('=')[::2]|map('trim')])) }}"
with_items: "{{ first_list }}"
- debug: var=final_list
您的输出将如下所示:
希望这能帮助你
来源:你好,Kelson,这与实际提供的链接不同。我需要从每个子列表中提取值。嗨,凯尔森,这确实有效。非常感谢。这是一个漂亮的解决方案,演示了如何使用Jinja过滤器实现更多功能。
TASK [debug] *********************************************************************************************************
ok: [localhost] => {
"final_list": {
"URL": "http://apps.introext.net/data.html",
"checksum": "7985e6b97a915ec6681b628c783fa2a52c6f055a",
"remotefile": "data.html"
}
}