在后台远程主机上的ansible run命令

时间:2016-09-06 10:59:04

标签: ansible ansible-playbook

我正在尝试使用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

1 个答案:

答案 0 :(得分:34)

我在评论中提到的link的简化回答:

---
- 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 &