[英]Are multiline matches supported in lineinfile?
我想匹配(並用一條注釋行刪除或替換)一行代碼塊:
daemon.*;mail.*;\
news.err;\
*.=debug;*.=info;\
*.=notice;*.=warn |/dev/xconsole
我試圖在lineinfile
它們與daemon(?:.|\\n)*xconsole
匹配,但是似乎沒有發生匹配:添加了替換行,但舊行仍然存在:
- name: remove xconsole from rsyslog.conf
lineinfile:
dest: /etc/rsyslog.conf
regexp: daemon(?:.|\n)*xconsole
state: absent
# also tried to add the next line to replace with a comment
#line: "# removed by ansible"
是否支持此類塊?
注意:我知道關於blockinfile
,它對於管理定界塊的添加/刪除非常blockinfile
。 我不認為它們可以與不可插入的塊(通過正則表達式匹配)一起使用。
否, lineinfile
搜索表達式,請參見模塊的源代碼 。
如果需要刪除/替換文本,請使用replace
模塊-它使用多行正則表達式,例如:
- name: remove xconsole from rsyslog.conf
replace:
dest: /etc/rsyslog.conf
# ensure regex is lazy!
regexp: daemon[\S\s]*?xconsole
replace: "# removed by ansible"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.