deploymentprocessansibledevops

Can Ansible keep a process running even after the playbook has ended?


i have an open-source program i want to run from ansible basically ansible will go into the node and run "./Program.Name" which will start the program but when ansible-playbook is done the program closes is there a way I can start the program and keep it running even after ansible is done? I was told there is the async module but how can I write the playbook so it will keep the program running for as long as the node is up. Please try to provide the yml code if possible where I can replace the name of the program and it should do the job

I have tried to run the porcess with "./Program.Name &" but it does not stay running.


Solution

  • The following methods may be useful to you, and the async and poll parameters are necessary,more info see ansible doc

    - name: run
      shell: "( tail > /dev/null 2>&1 &)"
      async: 10
      poll: 0
    

    Note: If you want to run the program with a daemon, I think supervisord may be more appropriate.