--- # task/main file for manage_apt_packages - name: "Update apt caches" ansible.builtin.apt: update_cache: yes cache_valid_time: 3600 - name: "Install/remove required packages" ansible.builtin.apt: name: "{{ item.name }}{% if item.version not in [None, '', 'latest'] %}={{ item.version }}{% endif %}" state: "{{ item.state }}" loop: "{{ manage_apt_packages_list }}" when: manage_apt_packages_list is defined and manage_apt_packages_list not in [None, ''] notify: "apt-autoremove"