New to Ansible. There has to be a simpler way to do this: I need to issue a command (e.g. ps), and go through the return elements one by one, skipping the first element which has the column headings (e.g. PID, etc. in this case). I am only interested in the process names, not the other column values.
What's the easiest way of doing this? Below is my approach (which may not be the best way). I finally whittled down the list to omit the first element. Do I read into a separate array, loop through each item, and use awk or sed to filter on the process name?
  name: Get process
  hosts: localhost
  tasks:
    - name: Get process
      command: "ps"
      register: ps_output
    - name: Set list length
      set_fact:
        array_end_index: "{{ ps_output.stdout_lines | length - 1 }}"
      
    - name: List all but last item
      debug: 
        msg: "{{ ps_output.stdout_lines[item] }}"
      loop: "{{ range(1, (array_end_index | int)) | list }}"
 
    