ansible執(zhí)行shell腳本的方法
1. 編寫腳本:pb_shell.sh
wfq@ubuntu:~/playbook$ cat pb_shell.sh #!bin/sh echo "today(`date`) is a nice day, since I do some nice demo about ansible and excute very well." > /home/wfq/playbook/pb.log wfq@ubuntu:~/playbook$
2. 執(zhí)行ansible命令,將腳本copy到其他幾臺(tái)服務(wù)器上
wfq@ubuntu:~/playbook$ ansible asb -m copy -a "src=/home/wfq/playbook/pb_shell.sh dest=/home/wfq/playbook/" 192.168.174.134 | success >> { "changed": true, "dest": "/home/wfq/playbook/pb_shell.sh", "gid": 1000, "group": "wfq", "md5sum": "79744ccf5b60c7d020bb261d11516252", "mode": "0664", "owner": "wfq", "size": 135, "src": "/home/wfq/.ansible/tmp/ansible-tmp-1523198762.69-211691352620479/source", "state": "file", "uid": 1000 } 192.168.174.131 | success >> { "changed": true, "dest": "/home/wfq/playbook/pb_shell.sh", "gid": 1000, "group": "wfq", "md5sum": "79744ccf5b60c7d020bb261d11516252", "mode": "0664", "owner": "wfq", "size": 135, "src": "/home/wfq/.ansible/tmp/ansible-tmp-1523198762.69-274155692570175/source", "state": "file", "uid": 1000 } 192.168.174.133 | success >> { "changed": true, "dest": "/home/wfq/playbook/pb_shell.sh", "gid": 1000, "group": "wfq", "md5sum": "79744ccf5b60c7d020bb261d11516252", "mode": "0664", "owner": "wfq", "size": 135, "src": "/home/wfq/.ansible/tmp/ansible-tmp-1523198764.85-163098225256987/source", "state": "file", "uid": 1000 } 192.168.174.132 | success >> { "changed": true, "dest": "/home/wfq/playbook/pb_shell.sh", "gid": 1000, "group": "wfq", "md5sum": "79744ccf5b60c7d020bb261d11516252", "mode": "0664", "owner": "wfq", "size": 135, "src": "/home/wfq/.ansible/tmp/ansible-tmp-1523198764.89-251052794120091/source", "state": "file", "uid": 1000 } wfq@ubuntu:~/playbook$
3. 執(zhí)行ansible命令,在每天服務(wù)器上執(zhí)行pb_shell.sh腳本
wfq@ubuntu:~/playbook$ ansible asb -m shell -a "sh /home/wfq/playbook/pb_shell.sh chdir=/home/wfq/playbook" 192.168.174.134 | success | rc=0 >> 192.168.174.131 | success | rc=0 >> 192.168.174.132 | success | rc=0 >> 192.168.174.133 | success | rc=0 >>
4. 比如,在131服務(wù)器,查看執(zhí)行生成的日志:
wfq@ubuntu:~/playbook$ cat pb.log today(2018年 04月 08日 星期日 22:46:19 CST) is a nice day, since I do some nice demo about ansible and excute very well. wfq@ubuntu:~/playbook$ wfq@ubuntu:~/playbook$ ls pb.log pb_shell.sh wfq@ubuntu:~/playbook$
到此這篇關(guān)于ansible執(zhí)行shell腳本的方法的文章就介紹到這了,更多相關(guān)ansible執(zhí)行shell腳本內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。