ansible 在后台远程主机上运行命令 [英] ansible run command on remote host in background
问题描述
我正在尝试使用 ansible 在多台主机上启动 filebeat(或就此而言,任何其他将按需连续运行的进程)进程.我不希望 ansible 等到进程继续运行.我想要 ansible 触发并忘记并出来并保持远程进程在后台运行.我尝试使用以下选项:
I am trying to start filebeat (or for that matter any other process which will run continuously on demand) process on multiple hosts using ansible. I don't want ansible to wait till the process keeps on running. I want ansible to fire and forget and come out and keep remote process running in back ground. I've tried using below options:
---
- hosts: filebeat
tasks:
- name: start filebeat
option a) command: filebeat -c filebeat.yml &
option b) command: nohup filebeat -c filebeat.yml &
option c) shell: filebeat -c filebeat.yml &
async: 0 //Tried without as well. If its > 0 then it only waits for that much of time and terminates the filebeat process on remote host and comes out.
poll: 0
推荐答案
来自 link 我在评论中提到:
Simplified answer from link I mentioned in the comment:
---
- hosts: centos-target
gather_facts: no
tasks:
- shell: "(cd /; python -mSimpleHTTPServer >/dev/null 2>&1 &)"
async: 10
poll: 0
注意子shell括号.
Note subshell parentheses.
更新:实际上,没有async
你应该没问题,只是不要忘记重定向标准输出:
Update: actually, you should be fine without async
, just don't forget to redirect stdout:
- name: start simple http server in background
shell: cd /tmp/www; nohup python -mSimpleHTTPServer </dev/null >/dev/null 2>&1 &
这篇关于ansible 在后台远程主机上运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!