--- - block: - name: "Check if package {{ package_name }} is already installed" ansible.builtin.command: rpm -q {{ package_name }} args: warn: no register: rpm_info changed_when: rpm_info.failed rescue: - name: "Add {{ package_name }} to the yum install list if missing" ansible.builtin.set_fact: packages_to_install: "{{ packages_to_install + [ package_name ] }}" when: rpm_info.failed