- name: apt upgrade
  become: true
  apt:
    update_cache: true
    upgrade: dist
  when: ansible_os_family == 'Debian'
- name: yum update
  become: true
  yum:
    name: '*'
    update_cache: true
    state: latest
  when: ansible_os_family == 'RedHat' and ansible_distribution_major_version|int == 7
- name: dnf update
  become: true
  dnf:
    name: '*'
    state: latest
  when: ansible_os_family == 'RedHat' and ansible_distribution_major_version|int >= 8
- name: install a python alternate to prevent ansible problems
  become: true
  apt:
    name: python-is-python3
  when: ansible_distribution == 'Ubuntu' and upgrade
- name: install nvidia driver before reboot
  apt:
    name: nvidia-driver-{{ nvidia_driver_version }}
  when: nvidia_driver_version
- name: upgrade kernel
  include_tasks: 'kernel/{{ansible_distribution}}.yml'
  when: (ansible_distribution == 'Debian' or ansible_distribution == 'CentOS') and ansible_virtualization_type != "docker"
- name: 系统源 重启
  become: true
  shell: reboot
  async: 0
  poll: 0
  register: reboot_result
  args:
    removes: /var/run/reboot-required
  when: reboot
- name: 系统源 重启等待
  local_action: wait_for host={{ ansible_ssh_host }} state=started
  when: reboot and reboot_result.changed
- name: 重新读取主机信息
  setup:
  when: reboot and reboot_result.changed
