0
点赞
收藏
分享

微信扫一扫

ansible【模块】linefile 文件行处理


文章目录

  • ​​1. 简介​​
  • ​​2. 示例​​
  • ​​2.1 文件内容修改​​
  • ​​2.2 在某一行前面插入一行​​
  • ​​2.3 在某一行后面插入一行​​
  • ​​2.4 删除某一行​​
  • ​​2.5 末尾加入一行​​
  • ​​2.6 替换或添加某一行​​

  • ​​ansible 快速学习手册​​

1. 简介

lineinfile:文件内容修改、在某行前面添加一行、在某行后面添加一行、删除某一行、末尾加入一行、替换或添加某一行

2. 示例

2.1 文件内容修改

其中regexp为要修改的源内容的正则匹配,line为修改后的内容
bbb修改为bbbbbb

ansible all -m lineinfile -a "dest=/root/test.txt regexp='bbb' line='bbbbbbb'"

2.2 在某一行前面插入一行

ansible all -m lineinfile -a "dest=/root/test.txt insertbefore='aa(.*)' line='eeee'"

2.3 在某一行后面插入一行

ansible all -m lineinfile -a "dest=/root/test.txt insertafter='aa(.*)' line='eeee'"

2.4 删除某一行

ansible all -m lineinfile -a "dest=/root/test.txt regexp='aa(.*)' state=absent"

2.5 末尾加入一行

ansible all -m lineinfile -a "dest=/root/test.txt line='hehe'"

2.6 替换或添加某一行

ansible all -m lineinfile -a "dest=/root/test.txt regexp='he(.*)' line='lllll' state=present"

举报

相关推荐

0 条评论