ansible 添加、删除、修改/etc/hosts
添加
1、编辑文件hosts.tml
vim hosts.tml
【
---
- hosts: 192.168.59.103
remote_user: root
tasks:
- name: add hosts
lineinfile: name=/etc/hosts line="192.168.59.103 www.test3.com"
】
2、验证
ansible-playbook hosts.yml
删除
1、编辑文件hosts.tml
vim hosts.tml
【
---
- hosts: 192.168.59.103
remote_user: root
tasks:
- name: absent hosts
lineinfile: name=/etc/hosts line="192.168.59.103 www.test3.com" state=absent
】
修改
1、编辑文件hosts.tml
vim hosts.tml
【
---
- hosts: 192.168.59.103
remote_user: root
tasks:
- name: replace hosts
#regexp:以192.168.59.103开头的一行替换成line:#192.168.59.103 www.test3.com
lineinfile: name=/etc/hosts regexp="^192.168.59.103" line="#192.168.59.103 www.test3.com"
#lineinfile: name=/etc/hosts regexp="192.168.59.103 www.test3.com" line="#192.168.59.103 www.test3.com"
】
转载请记录来源!!!!
https://www.cnblogs.com/leihongnu/