problem when I want to run a shell program on remote host in background

Hi Ansible Experts!

I use ansible 2.4.2.0 on linux Centos

I have one problem when I want to run a shell program on remote host in background

I have a shell program ControllerAgent like that :

[root@157501lepca02 bin]# pwd
/home/neoload69/bin
[root@157501lepca02 bin]# ls -l
total 320
-rwxr-xr-x 1 root root 13698 7 mars 09:04 ControllerAgent

If I run manually my shell program ControllerAgent as following :

[root@157501lepca02 bin]# nohup /home/neoload69/bin/ControllerAgent </dev/null >/dev/null 2>&1 &
[1] 10147
[root@157501lepca02 bin]#

it works well

But when I want to run my shell program ControllerAgent in a ansible playbook as following :

  • hosts: [xx.yyy.tt.xxx]
    become: yes
    remote_user: deploy75

  • name: Starting Controller Agent
    shell: sh nohup /home/neoload69/bin/ControllerAgent </dev/null >/dev/null 2>&1 &

Nothing happens, it means that no process of my shell program ControllerAgent is created

Do you have an idea of the problem to help me ?

Thanks a lots

Best regards

Viet

NB : the remote user deploy75 is in the visudo file of the remote machine xx.yyy.tt.xxx like

Allow root to run any commands anywhere

root ALL=(ALL) ALL
deploy75 ALL=(ALL) ALL

You are calling sh while shell already does this, also the nohup is
inside the sh so it won't prevent the disconnection race condition,
you need to execute the nohup directly:

shell:nohup /home/neoload69/bin/ControllerAgent </dev/null >/dev/null 2>&1 &

Also, I don't recommend doing this if you really want to run
backgrounded services like this you should use a service manager
(init.d, systemd, runit, upstart, etc)

Hi Brian

I have just done what you advice me

and it works, it is ok now

Thanks a lot

Best Regards

Nguyen