标签:ice line add system service top begin 添加 star
blockinfilepath 文件路径
block/content 添加的文本内容
state 删除absent ,默认present
insertbefore 在匹配的行前插入,=BOF,在文本前插入,默认是文本末尾
insertafter 在匹配的行后插入,=EOF,在文本后插入,默认是文本末尾
create =yes文件不存在就创建
marker 默认标记:# BEGIN ANSIBLE MANAGED BLOCK # END ANSIBLE MANAGED BLOCK
marker="#{mark}test(自定义)" 可以自定义标记名称
如果两次mark的标记相同,默认就是替换标记的内容
ansible jack6-2 -m blockinfile -a ‘path=/testdir/rc.local block="systemctl start mariadb\nsystemctl start httpd" insertafter=EOF‘
ansible jack6-2 -m blockinfile a ‘path=/testdir/rc.local block="systemctl stop mariadb\nsystemctl stop httpd" insertbefore=BOF marker=#{mark}service to start‘
ansible jack6-2 -m blockinfile -a ‘path=/testdir/test block="This is a test for add content" insertbefore="^This"‘
ansible jack6-2 -m blockinfile -a ‘path=/tmp/test block="Hello ansible,hi\nlineinfile\nEnsure a particular line is in a file,\nlineinfile -\nor replace an existing line using a back-referenced regular expression. " marker="#{mark} TEST FOR LINEINFILE" create=yes‘
path 文件路径
line 文本内容,替换或添加或删除的指定内容
regexp 正则匹配-------只处理最后一个匹配到的内容
insertbefore 和上个模块用法一样
insertafter 和上个模块用法一样
create=yes创建文件
state 和上个模块用法一样
backrefs 启用后向引用,就是类似sed的分组替换法
ansible jack6-2 -m lineinfile -a ‘path=/tmp/test line="test text"‘
ansible jack6-2 -m lineinfile -a ‘path=/tmp/test regexp="^line" line="I am a engine for IT"‘
ansible jack6-2 -m lineinfile -a ‘path=/tmp/test line="I am a engine for IT" state=absent‘
ansible jack6-2 -m lineinfile -a ‘path=/tmp/test line="I am Mr.wang" insertbefore="^Hello"‘
ansible jack6-2 -m lineinfile -a ‘path=/tmp/test regexp="(H.{4}).*(a.{4})" line="\2" backrefs=yes‘
ansible模块blockinfile/lineinfile
标签:ice line add system service top begin 添加 star
原文地址:https://blog.51cto.com/13434656/2525899