美文网首页
[ansible]ansible中的replace功能

[ansible]ansible中的replace功能

作者: Franckisses | 来源:发表于2018-12-26 14:37 被阅读24次

在ansible所有的模块中,有个replace模块,我们可以用这个模块来批量修改某个主机的配置文件。
来看看ansible-doc中对于replace的介绍:


文档内容

我们先来看看要修改的内容:
我们要将db主机上的i am fine 改为we are fine

    [root@db ~]# cat /new.txt 
    i am fine
    we are good 
    it is good example
    what should i do?

看命令:

[root@ansible ansible]# ansible db -m replace -a 'path=/new.txt regexp="^i am.*" replace="we are fine"'
db 为修改的主机
-m 指定的模块
replace 替换模块
path  修改文件的位置
regexp 用正则去匹配要修改的行
replace 要修改为什么内容

我们看看修改之后的内容为:

      [root@ansible ansible]# ssh db
      Last login: Wed Dec 26 14:28:31 2018 from 192.168.4.50
      [root@db ~]# cat /new.txt 
      we are fine
      we are good
      it is a good example
      what should i do?

到这我们就完美的实现了修改配置文件。

相关文章

网友评论

      本文标题:[ansible]ansible中的replace功能

      本文链接:https://www.haomeiwen.com/subject/thehlqtx.html