我正在从 Tower 启动 Ansible,然后将新用户填充为文本:
{ name: user1, uid: 5000 }
{ name: user2, uid: 5001 }
我想将这些用户作为字典进行迭代,例如:
- name: Print vars
debug:
var: "{{ item.name }}"
with_items: "{{ users.split('\n') }}"
但它不起作用:
TASK [Print vars] *********************************************************************************************************************
ok: [lx-test] => (item={ name: user1, uid: 5000 }) => {
"ansible_loop_var": "item",
"item": "{ name: user1, uid: 5000 }",
"{ name: user1, uid: 5000 }": "VARIABLE IS NOT DEFINED!"
}
ok: [lx-test] => (item={ name: user2, uid: 5001 }) => {
"ansible_loop_var": "item",
"item": "{ name: user2, uid: 5001 }",
"{ name: user2, uid: 5001 }": "VARIABLE IS NOT DEFINED!"
}
知道如何将该字符串转换为真正的字典吗?提前致谢!