当前位置:网站首页>ansible Lineinfile模块
ansible Lineinfile模块
2022-08-07 01:48:00 【Direct_】
文章目录
Lineinfile模块
ansible在使用sed进行替换时,经常会遇到需要转义的问题,而且ansible在遇到特殊符号进行替换时,存在问题,无法正常进行替换 。其实在ansible自身提供了两个模块:ineinfile模块和replace模块,可以方便的进行替换功能:相当于
sed,可以修改文件内容官网地址:https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html
常用参数:
| 参数 | 选项/默认值 | 说明 |
|---|---|---|
| path/dest | 目标文件绝对路径+文件名,必须参数 | |
| line | 替换/插入的内容 | |
| regexp | 待匹配内容 | |
| insertbefore | 匹配行前面插入 | |
| insertafter | 匹配行面插入 | |
| state | present / absent | 删除匹配行,需要将值设为 absent , 默认值 present |
| backup | yes / no | 是否在修改文件之前对文件进行备份。 yes/no |
| create | yes / no | 当要操作的文件并不存在时,是否创建对应的文件。yes/no |
| backrefs | 常和正则表达一起使用,如果正则表达不匹配,不做任何改变,如果匹配则替换匹配的内容 | |
| backrefs= | no | backrefs 为 no 时,如果没有匹配,则添加一行line。如果匹配了,则把匹配内容替被换为line内容 |
| backrefs= | yes | backrefs 为 yes 时,如果没有匹配,则文件保持不变。如果匹配了,把匹配内容替被换为line内容。 |
示例:
- 将 # 开头的行全部删除
[[email protected] ~]# ansible dong -m lineinfile -a "dest=/root/test state=absent regexp='^#'"
- 修改匹配到的内容
这里有个疑问?如果匹配格式为 “aaa.bbb.ccc” 我想要匹配 “aaa” 并修改,要怎么操作?参考下面的
replace模块
[[email protected] ~]# ansible dong -m lineinfile -a "path=/etc/selinux/config regexp='^SELINUX=' line='SELINUX=disabled'"
边栏推荐
- 6-8 求二叉树高度(20分)
- P4315 月下“毛景树”(树链剖分)
- 【第六篇】商城系统-实现规格参数和销售属性
- Multiple Dockets with the same group name are not supported.The following duplicate groups were disc
- HCIP练习04(重发布)
- Dark horse 2022 latest redis course notes and knowledge points (for interviews) are continuously updated
- bits and bytes
- 搭建Lua开发环境(Lua解释器+IDEA编译器)
- 分布式事务理论以及解决方案
- Pyhton知识点6——列表
猜你喜欢
随机推荐
存储中的爱情:cookie、本地存储、会话存储
如何分析友盟上给出的错误分析(stack trace)?
Multiple Dockets with the same group name are not supported.The following duplicate groups were disc
定义一个函数,接收三个参数返回一元二次方程
1323_STM32F103_ADC测试
【第六篇】商城系统-实现规格参数和销售属性
【音视频】srs直播平台搭建
xcode armv6 armv7 armv7s arm64
习题:选择结构(二)
decode()的用法
HCIP(18)
这个数据太骚!搞得我都激动了。
EventBus Series: User Guide for Index Subscriber Index in Event Bus 3.0
【Koltin Flow(三)】Flow操作符之中间操作符(三)
六安 自驾800公里大别山风景道,探索六安全域旅游
[Verilog Basics] Some basic concepts of DFT (Design for Test) testability design
单选项时过渡和动画
pytest collection (8) — API Functions
记一次To B开发普通的性能优化历程......报表优化
Download, install and use Nvm









