linuxansiblepid

Search for Linux Process (PID) using string query from Ansible


In Linux , I use below query to get the process id (PID) for process with name serverManager

ps -ef | grep serverManager

I need to perform the same activity in Ansible? I tried searching the API docs, but no luck

Can anyone tell me approach for this?


Solution

  • in ansible you can do any command you'd do in terminal with the shell module. However with the command you provided you can't retrieve the pid, I suggest you use pgrep.

    so the code should be

    - shell: pgrep serverManager
      register: servermanager_pid