--- - name: Update and upgrade apt packages hosts: all become: yes become_method: sudo tasks: - name: Update packages with apt when: ansible_pkg_mgr == 'apt' apt: update_cache: true - name: Upgrade packages with apt when: ansible_pkg_mgr == 'apt' command: sudo apt-get upgrade -y - name: Update packages with yum when: ansible_pkg_mgr == 'yum' ansible.builtin.yum: name: '*' state: latest # noqa: package-latest - name: Upgrade packages with yum when: ansible_pkg_mgr == 'yum' ansible.builtin.yum: name: '*' state: latest # noqa: package-latest exclude: kernel*