I have a register task to test for the installation of a package:
register
tasks: - name: test for nginx command: dpkg -s nginx-common register
It’s described in official documentation here.
tasks: - name: test for nginx command: dpkg -s nginx-common register: nginx_installed changed_when: false