[Ansible]lineinfile单⾏替换修改
在被管理的节点上⽤正则对⽬标⽂件的⼀⾏内容修改删除
在⼀个⽂件中匹配的多⾏统⼀处理参考
正则匹配多行⽂件中多⾏处理
path ⽬标⽂件路径
state absent删除
regexp 正则匹配最后⼀⾏被替换
line 要在⽂件中插⼊替换的⾏
create ⽂件不存在是,是否要创建⽂件内容 yes | no
[root@ceph3 tmp]# po
......
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source ←替换
#baseurl=/pub/epel/7/SRPMS
metalink=/metalink?repo=epel-source-7&arch=$basearch&infra=$infra&content=$contentdir failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
add  ←删除掉
- 删除匹配⾏
ansible webservers -m lineinfile -a "path=/po regexp='^add' state=absent"
- 替换某⼀⾏
ansible webservers -m lineinfile -a "path=/po regexp='^name=Extra' line='EXTRA'"
[epel-source]
EXTRA
#baseurl=/pub/epel/7/SRPMS
metalink=/metalink?repo=epel-source-7&arch=$basearch&infra=$infra&content=$contentdir failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
END

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。