[英]Multiple times adding same line into yaml file (ansible playbook)
我想在特定的行之間多次添加一行。 我嘗試使用我的劇本,但只添加到最后一個劇本,它應該添加與 From Earth 相同的行。
我的劇本
- name: Update the file
lineinfile:
dest: /sample/config.file
insertafter: ' Earth .* '
line: ' This is template'
我的初始文件
Hello World
[From Earth]
Hello World
[From Earth]
Hello World
[From Earth]
Hello World
[From Earth]
我的願望輸出
Hello World
[From Earth]
This is template
Hello World
[From Earth]
This is template
Hello World
[From Earth]
This is template
Hello World
[From Earth]
This is template
嘗試replace
:
- name: Replace
replace:
path: file.txt
regexp: 'Earth]\n(?!{{repl_str}})'
replace: 'Earth]\n{{repl_str}}'
vars:
repl_str: ' This is template\n'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.