[英]Execute shell script on server using Ansible
我必須使用 Ansible 在多台服務器上運行 shell 腳本。 我正在使用以下代碼。
-name: start script
hosts: list_of_host
become: yes
gather_facts: no
role:
- startscript
在startscript中我有下面的代碼......
-name: start script
shell: /bin/bash /home/ansible/test_script.sh
chnaged_when: false
Test_script 永遠在服務器上運行進程。 所以當我執行這個命令時,它不是從那個服務器出來的。 我需要它應該在服務器上啟動腳本並出來並 go 到另一台服務器以啟動腳本。
如果/home/ansible/test_script.sh
是“永遠運行”,您應該將其轉換為服務並通過 systemctl 啟動它。
顯然 ansible 將等待shell:
命令完成..
shell
不應用於“永遠運行”的腳本。
您也可以通過啟動screen
並在其中執行腳本來啟動/home/ansible/test_script.sh
,這樣它會在 ansible 退出后繼續運行,
或者您可以嘗試通過在shell:
命令的末尾添加&
將該腳本推送到后台執行,並在命令前加上nohup
以便在 ansible 的 ssh 連接斷開時不會終止
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.