使用Ansible从配置文件中删除文本块 [英] remove block of text from config file using ansible
本文介绍了使用Ansible从配置文件中删除文本块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从samba配置文件smb.conf中删除以下部分.
I am trying to remove the below section from samba config file smb.conf.
[public]
path = /opt/samba/public
guest ok = yes
browsable = yes
writable = yes
read only = no
由于没有标记,Blockinfile模块将无法工作. Lineinfile也将存在问题,因为其他部分共有一些行.例如
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
browsable = yes
writable = yes
如何使用Ansible删除这些行?
How do I remove these lines using ansible?
PS:不可能用新文件替换配置文件,因为每个服务器都有一个映射到其的唯一用户(运行批处理作业时不理想)
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)
推荐答案
您可以使用替换模块:
- replace:
path: /etc/smb.conf
regexp: '^\[public\][^[]+'
replace: ''
backup: yes
这应该删除[public]
和[
或EOF
之间的所有内容.
This should remove everything between [public]
and [
or EOF
.
这篇关于使用Ansible从配置文件中删除文本块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文