微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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"


版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐