remove block of text from config file using ansible
You can use replace module:
- replace:
path: /etc/smb.conf
regexp: '^\[public\][^[]+'
replace: ''
backup: yes
This should remove everything between [public]
and [
or EOF
.
Ansible has native ini-file support, which is a much cleaner way to accomplish this.
- name: remove public block
ini_file:
path: /etc/smb.conf
section: public
state: absent
Here is one that will remove the entire tag in an apache config file:
replace:
path: "{{my_path}}"
regexp: '^<Directory /var/www/>(.*\n)*</Directory>$'
replace: ''