Ansible文件内容修改lineinfile模块(学习笔记五)

2022-05-24 17:05:53 浏览数 (1)

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

1、文件内容修改,其中regexp为要修改的源内容的正则匹配,line为修改后的内容:ansible all -m lineinfile -a "dest=/root/test.txt regexp='bbb' line='bbbbbbb'"

image.png

2、在某一行前面插入一行:ansible all -m lineinfile -a "dest=/root/test.txt insertbefore='aa(.*)' line='eeee'"

image.png

3、在某一行后面插入一行,insertafter

4、删除某一行:ansible all -m lineinfile -a "dest=/root/test.txt regexp='aa(.*)' state=absent"

image.png

5、末尾加入一行: ansible all -m lineinfile -a "dest=/root/test.txt line='hehe'"

image.png

6、替换或添加某一行:ansible all -m lineinfile -a "dest=/root/test.txt regexp='he(.*)' line='lllll' state=present"

image.png

7、也可以添加参数owner,group,mode

0 人点赞