Ansible——replace模块

replace模块根据指定的正则表达式替换文件中的字符串,文件中所有被匹配到的字符串都会被替换。

一、常用参数

path:required,指定要操作的文件。
regexp: required,指定一个 python 正则表达式,文件中与正则匹配的字符串将会被替换。
replace: 指定最终要替换成的字符串。
backup:是否在修改文件之前对文件进行备份,默认为no。

二、示例

示例1
把 host1 主机中的 /testdir/test 文件中的所有 ABC 替换成 abc。

[root@ansible-manager ~]# ansible host1 -m replace -a 'path=/testdir/test regexp="ABC" replace=abc'

示例2
把 host1 主机中的 /testdir/test 文件中的所有 ABC 替换成 abc,但是在操作文件之前进行备份。

[root@ansible-manager ~]#ansible host1 -m replace -a 'path=/testdir/test regexp="ABC" replace=abc backup=yes'

————Blueicex 2020/2/2 16:56 [email protected]

发布了55 篇原创文章 · 获赞 0 · 访问量 2015

猜你喜欢

转载自blog.csdn.net/blueicex2017/article/details/104146547