community.general.pids (8.5.0) — module

Retrieves process IDs list if the process is running otherwise return empty list

Authors: Saranya Sridharan (@saranyasridharan)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Retrieves a list of PIDs of given process name in Ansible controller/controlled machines.Returns an empty list if no process in that name exists.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Pass the process name
- name: Getting process IDs of the process
  community.general.pids:
      name: python
  register: pids_of_python
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Printing the process IDs obtained
  ansible.builtin.debug:
    msg: "PIDS of python:{{pids_of_python.pids|join(',')}}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Getting process IDs of processes matching pattern
  community.general.pids:
    pattern: python(2(\.7)?|3(\.6)?)?\s+myapp\.py
  register: myapp_pids

Inputs

    
name:
    description: The name of the process(es) you want to get PID(s) for.
    type: str

pattern:
    description: The pattern (regular expression) to match the process(es) you want to
      get PID(s) for.
    type: str
    version_added: 3.0.0
    version_added_collection: community.general

ignore_case:
    default: false
    description: Ignore case in pattern if using the O(pattern) option.
    type: bool
    version_added: 3.0.0
    version_added_collection: community.general

Outputs

pids:
  description: Process IDs of the given process
  returned: list of none, one, or more process IDs
  sample:
  - 100
  - 200
  type: list