Skip to content


use ansible to scan for a process

How to scan a group of hosts for a particular process with Ansible?

---
- hosts: all
  gather_facts: no
  vars_prompt:
   - name: "proc_name"
     prompt: "Enter process name to look for"
     private: no

  tasks:
  - name: "check for the {{ proc_name }} process"
    shell: "ps -e | grep -v grep | grep -w {{ proc_name }}"
    register: ps_output
    failed_when: false
    no_log: True
  - debug:
      msg: "{{ ps_output.stdout_lines }}"
    when: ps_output.rc == 0

To do something similar from a command line – for example to find all hosts running “kworker” process or processes:

# ansible all -m shell -a "ps -e | grep -v grep | grep -w kworker"

Posted in LINUX.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.

WordPress Anti Spam by WP-SpamShield



Copyright © 2016 - 2018 Waldemar Mark Duszyk. All Rights Reserved. Created by Blog Copyright.