Ansible run command on a remote host in the background

I am trying to run filebeat (or, for that matter, any other process that will run continuously on demand) on multiple hosts using ansible. I do not want to wait until the process continues. I want to be able to shoot, forget and leave, and the remote process to work in the background. I tried using the following 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 
+7
ansible ansible-playbook
source share
1 answer

The simplified answer from the 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 

Note the brackets in parentheses.

Update: in fact, you should be fine without async , just remember to redirect stdout:

 - name: start simple http server in background shell: cd /tmp/www; nohup python -mSimpleHTTPServer </dev/null >/dev/null 2>&1 & 
+14
source share

All Articles