I recently started upgrading my servers and containers to Ubuntu 20.04. I made three Ansible playbooks to get information about which hosts I needed to update.

Reboot required

Lists servers that have pending kernel updates and needs to be rebooted.

---
- hosts: all !containers
  vars:
    ansible_python_interpreter: /usr/bin/python3
  tasks:
    - name: check if a reboot is required
      shell: "[ -f /var/run/reboot-required ]"
      failed_when: False
      register: reboot_required
      changed_when: reboot_required.rc == 0
      notify: user_message

  handlers:
    - name: user_message
      debug:
        msg: "Reboot required"

Outputs:

ok: [alpha.lan.uctrl.net] => {
    "msg": "Reboot required"
}

Ubuntu version

Lists hosts which have Ubuntu version below 20.0.

---
- hosts: all
  vars:
    ansible_python_interpreter: /usr/bin/python3
  gather_facts: yes
  become: false
  tasks:
    - name: System details
      debug:
        msg: '{{ ansible_distribution }} {{ ansible_distribution_version }}'
      when:
        - ansible_distribution == "Ubuntu"
        - ansible_distribution_version is version('20.0', operator='lt', strict=True)

Outputs:

ok: [alpha.lan.uctrl.net] => {
    "msg": "Ubuntu 18.04"
}
skipping: [zeta.lan.uctrl.net]
skipping: [epsilon.lan.uctrl.net]
skipping: [omicron.lan.uctrl.net]

Kernel version

Lists servers with kernel version below 5.0

---
- hosts: servers
  become: yes
  vars:
    kernel_version: "{{ ansible_kernel.split('-')|first }}"
    ansible_python_interpreter: /usr/bin/python3
  tasks:
    - name: 'kernel version from facts'
      debug:
        msg: '{{ ansible_kernel }}'
      when:
        - kernel_version is version('5.0', operator='lt', strict=True)

Outputs:

ok: [alpha.lan.uctrl.net] => {
    "msg": "4.15.0-135-generic"
}
skipping: [zeta.lan.uctrl.net]
skipping: [epsilon.lan.uctrl.net]
skipping: [omicron.lan.uctrl.net]