---
- name: Gather Nomad debug information from multiple nodes
  hosts: all
  become: yes
  tasks:
    - name: Get Nomad service status
      shell: systemctl status nomad --no-pager -l
      register: nomad_status
      changed_when: false
      failed_when: false

    - name: Get last 50 lines of Nomad journal logs
      shell: journalctl -u nomad -n 50 --no-pager
      register: nomad_journal
      changed_when: false
      failed_when: false

    - name: Display Nomad Status
      debug:
        msg: |
          --- Nomad Status for {{ inventory_hostname }} ---
          {{ nomad_status.stdout }}
          {{ nomad_status.stderr }}

    - name: Display Nomad Journal
      debug:
        msg: |
          --- Nomad Journal for {{ inventory_hostname }} ---
          {{ nomad_journal.stdout }}
          {{ nomad_journal.stderr }}