在变量中使用dict2items过滤器来将字典转换为可迭代的项列表,然后再遍历这个列表。
示例代码:
- set_fact:
my_dict:
name: John
age: 30
city: New York
- debug:
msg: "{{ item.key }} is {{ item.value }}"
with_items: "{{ my_dict | dict2items }}"
上一篇:Ansible:将‘AnsibleUnsafeText’转换为‘int’返回零。
下一篇:Ansible:Noinventorywaspassed,onlyimplicitlocalhostisavailable