Soubhik Banerjee
Soubhik Banerjee

Reputation: 441

List running java processes in a linux host via ansible playbook

I want to list the java processes running in the mentioned hosts. However am not getting the desired o/p

Have created a ansible-playbook file to read the shell commands.

 name: 'Check the running java processes'
 hosts: all
 tasks:
   - name: 'check running processes'
     shell: ps -ef | grep -i java```

output: PLAY [Check the running java processes] ****************************************

TASK [setup] *******************************************************************
ok: [target1]
ok: [target2]

TASK [check running processes] *************************************************
changed: [target1]
changed: [target2]

PLAY RECAP *********************************************************************
target1                    : ok=2    changed=1    unreachable=0    failed=0   
target2                    : ok=2    changed=1    unreachable=0    failed=0   

However, it's not listing the processes.

Upvotes: 1

Views: 4823

Answers (1)

Zeitounator
Zeitounator

Reputation: 44760

You could see the result with your actual playbook by running ansible in verbose mode.

However, the good way to do this is to register the output of your task and display its content in a debug task (or use it in any other task/loop).

To know how your registered var looks like, you can read the doc about common and shell's specific return values... or you can simply debug the full var in your playbook and have a look at it.

Here is an example just to get the full stdout of the command:

---
- name: Check the running java processes
  hosts: all
  tasks:
    - name: Check running processes
      shell: ps -ef | grep -i java
      register: ps_cmd

    - name: Show captured processes
      debug:
        var: ps_cmd.stdout

Upvotes: 1

Related Questions