ansible在后台远程主机上运行命令

ansible在后台远程主机上运行命令,ansible,ansible-playbook,Ansible,Ansible Playbook,我正在尝试使用ansible在多台主机上启动filebeat(或任何其他按需连续运行的进程)进程。我不希望ansible等到进程继续运行。我希望ansible开火,然后忘记,然后出来,让远程进程在后台运行。 我已尝试使用以下选项: --- - hosts: filebeat tasks: - name: start filebeat option a) command: filebeat -c filebeat.yml & option b)

我正在尝试使用ansible在多台主机上启动filebeat(或任何其他按需连续运行的进程)进程。我不希望ansible等到进程继续运行。我希望ansible开火,然后忘记,然后出来,让远程进程在后台运行。 我已尝试使用以下选项:

    ---
    - 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
我在评论中提到的简化答案:

---
- hosts: centos-target
  gather_facts: no
  tasks:
    - shell: "(cd /; python -mSimpleHTTPServer >/dev/null 2>&1 &)"
      async: 10
      poll: 0
注意子shell括号

更新:实际上,如果没有
async
,您应该不会有问题,只是别忘了重定向stdout:

- name: start simple http server in background
  shell: cd /tmp/www; nohup python -mSimpleHTTPServer </dev/null >/dev/null 2>&1 &
-name:在后台启动简单http服务器
shell:cd/tmp/www;nohup python-mSimpleHTTPServer/dev/null 2>&1&

请看一看:我已经对那篇文章发表了评论,其中使用daemon命令对我无效。“异步”和“轮询”选项是什么?它们没有被记录()您是如何终止进程的?@dokaspar它们被记录在另一个地方:。