ansible執(zhí)行shell腳本的方法
更新時間:2021年09月10日 15:34:12 作者:wang725
本文主要介紹了ansible執(zhí)行shell腳本的方法,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
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到其他幾臺服務(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)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Linux壓縮及解壓縮命令tar|zip|rar|xz操作方法
不管Linux還是其他操作系統(tǒng),數(shù)據(jù)的壓縮和解壓縮操作是經(jīng)常用到的,在windows平臺文件的相關(guān)操作被傻瓜化了,到了Linux平臺讓好多小伙伴感覺有點(diǎn)束手無策,本文為大家講解Linux的常用壓縮包操作,格式包含tar.gz, .tgz, .tar.bz2, .zip, .rar, .tar.xz,感興趣的朋友一起看看吧2024-02-02Linux 中shell腳本設(shè)置開頭固定格式的實(shí)現(xiàn)方法
這篇文章主要介紹了Linux 中shell腳本設(shè)置開頭固定格式的實(shí)現(xiàn)方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10