Soumya Simanta
Soumya Simanta

Reputation: 11751

Using ansible to launch a long running process on a remote host

I'm new to Ansible. I'm trying to start a process on a remote host using a very simple Ansible Playbook.

Here is how my playbook looks like

-
  hosts: somehost
  gather_facts: no
  user:  ubuntu  
  tasks:
    - name: change directory and run jetty server
      shell: cd /home/ubuntu/code; nohup ./run.sh    
      async: 45

run.sh calls a java server process with a few parameters. My understanding was that using async my process on the remote machine would continue to run even after the playbook has completed (which should happen after around 45 seconds.)

However, as soon as my playbook exits the process started by run.sh on the remote host terminals as well.

Can anyone explain what's going and what am I missing here.

Thanks.

Upvotes: 4

Views: 8493

Answers (3)

rogue-one
rogue-one

Reputation: 11587

I have ansible playbook to deploy my Play application. I use the shell's command substitution to achieve this and it does the trick for me. I think this is because command substitution spawns a new sub-shell instance to execute the command.

-
  hosts: somehost
  gather_facts: no
  user:  ubuntu  
  tasks:
    - name: change directory and run jetty server
      shell: dummy=$(nohup /run.sh &) chdir={{/home/ubuntu/code}}

Upvotes: 5

user1451035
user1451035

Reputation:

I'd concur. Since it's long running, I'd call it a service and run it like so. Just create an init.d script, push that out with a 'copy' then run the service.

Upvotes: 2

guest
guest

Reputation: 56

Give a longer time to async say 6 months or an year or evenmore and this should be fine. Or convert this process to an initscript and use the service module.

and add poll: 0

Upvotes: 4

Related Questions