我需要向配置文件之一添加新字符串。我必须在“ images =“中添加带有“,”的“ mycustomimage”。简而言之,我需要的输出是images = previousimage,mycustomimage
mycnf.conf的视图
id=1
images=previousimage
为此,我尝试了此代码
---
- hosts: test_server
- name: Add new string after "," in images
lineinfile:
path: /home/mycnf.conf
regexp: 'images='
insertafter: '^,'
line: mycustomimage
预期输出
id= 1
images=previousimage,mycustomimage
但是它对我不起作用。有什么想法吗?提前致谢!Sid
根据您的示例
images=previousimage,mycustomimage
image=.*
行(如果存在且与最后一行不匹配。)>以下将完成工作
- name: Replace line if needed
lineinfile:
path: config.txt
regex: images=.*
line: images=previousimage,mycustomimage