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

Mru*_*sar 23 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
Run Code Online (Sandbox Code Playgroud)

Kon*_*rov 40

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

---
- hosts: centos-target
  gather_facts: no
  tasks:
    - shell: "(cd /; python -mSimpleHTTPServer >/dev/null 2>&1 &)"
      async: 10
      poll: 0
Run Code Online (Sandbox Code Playgroud)

注意子shell括号.

更新:实际上,你应该没事async,只是不要忘记重定向stdout:

- name: start simple http server in background
  shell: cd /tmp/www; nohup python -mSimpleHTTPServer </dev/null >/dev/null 2>&1 &
Run Code Online (Sandbox Code Playgroud)

  • 您的解决方案奇迹般地工作。非常感谢队友 (2认同)
  • “异步”和“轮询”选项是什么?它们没有记录(http://docs.ansible.com/ansible/latest/shell_module.html) (2认同)
  • 你是怎么杀掉这个进程的? (2认同)