If you want to ensure a list of packages is absent, make a task that does only that.
- name: "Borramos el paquete"
package:
name: "{{ package_names }}"
state: absent
Each Ansible task describes a desired state when the task is completed. You don't need to check whether the packages are installed. You only need to say you want them absent. If any (or all) of the packages are present, they will be removed, the task will report "changed", and the state will be changed. If none of the packages are present, the task will report "ok" and the state will be unchanged.
--
Walter Rowe, Chief
Infrastructure Services
Office of Information Systems Management
National Institute of Standards and Technology
United States Department of Commerce