我想知道是否可以使用模块lineinfile或其他模块在同一行中插入两个或更多项。就像这个例子:
- name: Insert content in the File
lineinfile:
dest: /tmp/file.txt
line: 'Groups = {{ item }}'
create: yes
with_items:
- "{{ group_ad }}"
group_ad:
- LINUX
- DBA在文件中,在执行攻略之后保持该状态:
Groups = LINUX
Groups = DBA但我想保持如下所示:
Groups = LINUX, DBA我做的是谁?
发布于 2021-01-14 23:33:53
您正在迭代列表,但是您想要添加列表。因此在这里使用join更容易
- name: Insert content in the File
lineinfile:
dest: /tmp/file.txt
line: 'Groups = {{ group_ad | join(', ') }}'
create: yeshttps://stackoverflow.com/questions/65721476
复制相似问题