- name: amd64 arch
  set_fact:
    install_kernel_arch: amd64
  when: ansible_architecture == 'x86_64'
- name: arm64 arch
  set_fact:
    install_kernel_arch: arm64
  when: ansible_architecture == 'aarch64'
- name: use non-cloud kernel
  set_fact:
    install_kernel_name: linux-image-{{install_kernel_arch}},linux-headers-{{install_kernel_arch}}
  when: cloud_kernel == "disabled" or cloud_kernel == "auto" and not (ansible_virtualization_role == "guest" and ansible_virtualization_type == "kvm")
- name: use cloud kernel
  set_fact:
    install_kernel_name: linux-image-cloud-{{install_kernel_arch}},linux-headers-cloud-{{install_kernel_arch}}
  when: cloud_kernel == "enabled" or cloud_kernel == "auto" and ansible_virtualization_role == "guest" and ansible_virtualization_type == "kvm"
- name: install kernel
  become: true
  apt:
    name: '{{install_kernel_name}}'
    state: latest
    update_cache: true
    default_release: '{{ target_distribution }}-backports'
  when: ansible_distribution_release != 'sid'
- name: check RTL8111
  shell: 'lspci | grep RTL8111'
  register: check_rtl_result
  changed_when: false
  failed_when: 'check_rtl_result.rc > 1'
- name: install RTL8111 driver
  become: true
  apt:
    name: r8168-dkms
    default_release: '{{ target_distribution }}-backports'
  when: check_rtl_result.rc == 0 and ansible_distribution_release != 'sid'
- name: install RTL8111 driver for sid
  become: true
  apt:
    name: r8168-dkms
  when: check_rtl_result.rc == 0 and ansible_distribution_release == 'sid'
- name: check b43
  shell: 'lspci | grep BCM4322'
  register: check_b43_result
  changed_when: false
  failed_when: 'check_b43_result.rc > 1'
- name: install b43 driver
  become: true
  apt:
    name: firmware-b43-installer
  when: check_b43_result.rc == 0
- name: remove wireguard-dkms
  become: true
  apt:
    name: wireguard-dkms
    state: absent
    purge: true
