---
- name: Gather debug info
  hosts: "{{ _hosts | default(omit) }}"
  become: true

  tasks:
    - name: Gather recent vmstat info  # noqa: no-changed-when
      ansible.builtin.command: /bin/vmstat 1 5
      register: vmstat

    - name: Gather top CPU hogs  # noqa: no-changed-when
      ansible.builtin.command: ps -eo user,pid,size,pcpu,cmd --sort=-pcpu
      register: pscpu

    - name: Gather top memory hogs  # noqa: no-changed-when
      ansible.builtin.command: ps -eo user,pid,size,pcpu,cmd --sort=-size
      register: pssize

    - name: Swap + wait states
      ansible.builtin.debug:
        var: vmstat.stdout_lines

    - name: Top 3 CPU hogs
      ansible.builtin.debug:
        var: pscpu.stdout_lines[:4]

    - name: Top 3 memory hogs
      ansible.builtin.debug:
        var: pssize.stdout_lines[:4]
