---

- block:
  - name: install kernel {{ kernel_version }}
    apt:
      name:
        - "linux-image-{{ kernel_version }}-{{ kernel_category }}"
        - "linux-headers-{{ kernel_version }}-{{ kernel_category }}"
      state: present
      update_cache: yes
      cache_valid_time: 3600
    notify:
      - reboot host
      - wait for reboot
  # AWS-optimized kernels already have "extras"
  - name: install kernel extras {{ kernel_version }}
    apt:
      name: "linux-image-extra-{{ kernel_version }}-{{ kernel_category }}"
      state: present
      update_cache: yes
      cache_valid_time: 3600
    when: kernel_category != "aws"
    notify:
      - reboot host
      - wait for reboot
  become: yes
