regex - Are multiline matches supported in lineinfile? -


i match (and remove or replace 1 commented line) block of lines:

daemon.*;mail.*;\         news.err;\         *.=debug;*.=info;\         *.=notice;*.=warn       |/dev/xconsole 

i tried match them in lineinfile daemon(?:.|\n)*xconsole match not seem happen: replacement line added old line remains:

  - name: remove xconsole rsyslog.conf     lineinfile:       dest: /etc/rsyslog.conf       regexp: daemon(?:.|\n)*xconsole       state: absent       # tried add next line replace comment       #line: "# removed ansible" 

are such blocks supported?

note: know blockinfile great manage addition/removal of delimited blocks. not believe work non-ansible-inserted blocks (matched though regex).

no, lineinfile search expression line line, see module's source code.

if need remove/replace text, use replace module – use multiline regex, e.g.:

 - name: remove xconsole rsyslog.conf     replace:       dest: /etc/rsyslog.conf       # ensure regex lazy!       regexp: daemon[\s\s]*?xconsole       replace: "# removed ansible" 

Comments