我有一个以下格式的列表,需要用反冲替换逗号,但在尝试使用替换功能时出错。
"sub_keys": [
",,ps1,printer1",
",,ps1,printer2",
",,ps2,printer1"]
expected result:
new_list:[ "\ps1printer1",
"\ps1printer2"
"\ps2printer1"]
我尝试了以下代码:
- name: Convert list
set_fact:
new_list: '{{ new_list + [item.replace (",","")] }}'
with_items: "{{ sub_keys }}"
你试过吗:
- name: Convert list
set_facts:
new_list:
- "\\ps1\printer1"
- "\\ps1\printer2"
- "\\ps2\printer1"