[英]Execute shell script on server using Ansible
I have to run shell script on multiple server using Ansible.我必须使用 Ansible 在多台服务器上运行 shell 脚本。 I am using following code.
我正在使用以下代码。
-name: start script
hosts: list_of_host
become: yes
gather_facts: no
role:
- startscript
in startscript i have below code...在startscript中我有下面的代码......
-name: start script
shell: /bin/bash /home/ansible/test_script.sh
chnaged_when: false
Test_script is forever running process on sever. Test_script 永远在服务器上运行进程。 so when i am executing this command it's not coming out from that server.
所以当我执行这个命令时,它不是从那个服务器出来的。 I need that it should start script on server and come out and go to another server to start script.
我需要它应该在服务器上启动脚本并出来并 go 到另一台服务器以启动脚本。
If /home/ansible/test_script.sh
is "forever running", you should convert that to a service and start it via systemctl.如果
/home/ansible/test_script.sh
是“永远运行”,您应该将其转换为服务并通过 systemctl 启动它。
Obviously ansible would wait for the shell:
command to complete..显然 ansible 将等待
shell:
命令完成..
shell
should not be used for "forever running" scripts. shell
不应用于“永远运行”的脚本。
You can also start the /home/ansible/test_script.sh
by starting a screen
and executing the script within it, so it continues to run after ansible exits,您也可以通过启动
screen
并在其中执行脚本来启动/home/ansible/test_script.sh
,这样它会在 ansible 退出后继续运行,
or you can try and push that script to background execution by adding &
at the end of your shell:
command, as well as prefixing the command with nohup
so it is not terminated when ansible's ssh connection disconnects或者您可以尝试通过在
shell:
命令的末尾添加&
将该脚本推送到后台执行,并在命令前加上nohup
以便在 ansible 的 ssh 连接断开时不会终止
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.