温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ansible 相关命令备忘

发布时间:2020-04-06 18:22:21 来源:网络 阅读:317 作者:余伟兵 栏目:系统运维

常用的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"


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI