- hosts: demo
  gather_facts: no
  tasks:
    - name: Gather posix account
      ansible.builtin.shell:
        cmd: >
          users=$(getent passwd | grep -v nologin | grep -v shutdown | awk -F":" '{ print $1 }');for i in $users;
          do k=$(last -w -F $i -1 | head -1 | grep -v ^$ | awk '{ print $0 }')
            if [ -n "$k" ]; then
              echo $k
            else
              echo $i
            fi;done
      register: result

    - name: Define info by set_fact
      ansible.builtin.set_fact:
        info: "{{ result.stdout_lines }}"

    - debug:
        var: info