'Ansible: Show last X output lines

Is there a way to output only the last 5 lines of an Ansible shell output, for example?
Maybe using loops?

Example:

  - name: Running Migrations
    ansible.builtin.shell: /some-script-produces-lot-of-output.sh
    register: ps
  - debug: var=ps.stdout_lines

Debug should only output the last 5 lines.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source