remove block of text from config file using ansible


I am trying to remove the below section from samba config file smb.conf.

Blockinfile module won’t work as there are no markers . Lineinfile will also have a problem as there are lines which are common to other sections. e.g

How do I remove these lines using ansible?

PS: replacing the config file with a new one is not possible as each server has a unique user mapped to it (not ideal when running batch jobs)


You can use replace module:

This should remove everything between [public] and [ or EOF.

Leave a Reply