--- - name: Update and upgrade apt packages hosts: all tasks: - name: Update packages with apt when: ansible_pkg_mgr == 'apt' ansible.builtin.apt: update_cache: true - name: Update packages with yum when: ansible_pkg_mgr == 'yum' ansible.builtin.yum: name: '*' state: latest - name: Upgrade packages with apt when: ansible_pkg_mgr == 'apt' ansible.builtin.apt: upgrade: dist - name: Upgrade packages with yum when: ansible_pkg_mgr == 'yum' ansible.builtin.yum: name: '*' state: latest exclude: kernel*