ansible 相关命令备忘
作者:互联网
常用的ansible命令,备忘。
一、修改/etc/ansible/hosts文件,将需要操作的主机添加进去:
vi /etc/ansible/hosts
[ywbhost]
192.16.1.[29:52] ansible_ssh_uer="root" ansible_ssh_pass="xxxxxx"
二、执行shell命令:
ansible ywbhost -m shell -a "/tmp/setdns.sh"
三、复制文件
复制文件到远端主机copy:
ansible ywbhost -m copy -a "src=/etc/ansible/ywb/setdns.sh dest=/tmp/setdns.sh mode=755"
从远端主机拷贝文件到本机,fetch:
ansible ywbhost -m fetch -a "src=/tmp/setdns.sh dest=/tmp/setdns.sh mode=755"
四、文本操作:
1、在文末添加一行
ansible ywbhost -m lineinfile -a "dest=/etc/chrony.conf line='server 192.168.1.33 iburst'"
2、替换一行
ansible all -m lineinfile -a "dest=/root/test.txt regexp='bbb' line='bbbbbbb'"
3、在某一行前面插入一行:
ansible all -m lineinfile -a "dest=/root/test.txt insertbefore='aa(.*)' line='eeee'"
4、在某一行后面插入一行,insertafter
ansible all -m lineinfile -a "dest=/root/test.txt insertafter='aa(.*)' line='eeee'"
5、删除某一行:
ansible all -m lineinfile -a "dest=/root/test.txt regexp='aa(.*)' state=absent"
6、替换或添加某一行:ansible all -m lineinfile -a "dest=/root/test.txt regexp='he(.*)' line='lllll' state=present"
标签:setdns,dest,lineinfile,备忘,命令,ansible,txt,root 来源: https://blog.51cto.com/yuweibing/2455416