【发布时间】:2020-04-18 06:23:21
【问题描述】:
我需要在文件中的参数末尾添加一个文本。我需要在</abc> 之前插入我的文本。我正在使用 lineinfile,它在<abc> 之前输入文本而不是</abc>。
我当前的文本文件:
<domain-log-broadcast-filter>MultiDataSourceLogFilter</domain-log-broadcast-filter> <abc>Info is already here. i just need to append the text at end of this parameter. new values to be inserted here</abc>
我的剧本:
- lineinfile:
path: /tmp/tochange.xml
insertbefore: '\<\/abc\>'
line: "Tisisthelinetobeinsertedbyme"
state: present
我的输出是:
<domain-log-broadcast-filter>MultiDataSourceLogFilter</domain-log-broadcast-filter> Thisisthelinetobeinsertedbyme <abc>Info is already here. i just need to append the text at end of this parameter. new values to be inserted here</abc>
现在我有两个要求:
- 我想在
</abc>之前插入我的文本 - 我的文件中有 4 个
</abc>参数。我想忽略第一个</abc>并在其他 3 个</abc>参数之前插入该行。
请给我一个最好的方法,我只需要完成这项工作,使用剧本中的任何模块任何脚本。提前致谢。
【问题讨论】:
标签: shell ansible devops ansible-template