【发布时间】:2021-06-01 19:11:33
【问题描述】:
我有一些变量需要循环:
mariadb_grants:
"*.*":
- user1: "ALL, SELECT"
- user2: "ALL"
"toto":
- user1: "ALL"
- user23: "GRANT"
当然,userX 没有预先定义,我可以有 user1233 等。 我可以用这段代码很容易地循环遍历字典:
tasks:
- debug:
msg: "Key is {{ item }} and value is {{ mariadb_grants[item] }}"
loop: "{{ mariadb_grants.keys() }}"
我知道了:
ok: [localhost] => (item=*.*) => {}
MSG:
Key is *.* and value is [{'user1': 'ALL, SELECT'}, {'user2': 'ALL'}]
ok: [localhost] => (item=toto) => {}
MSG:
Key is toto and value is [{'user1': 'ALL'}, {'user23': 'GRANT'}]
我正在尝试做的事情就是获取 userx 的键和值,基本上我想要这个:
My key is *.* I'm user1 and my value is "ALL, SELECT"
My key is *.* I'm user2 and my value is ALL
My key is "toto" I'm user1 and my value is ALL
[...]
似乎我无法遍历我的子元素:(
【问题讨论】: