How to control when notify gets triggered by i.e. command

Hi,

I have for an example an task which enables modules in apache2 in debian with the command a2enmod.

So I have:

  • name: Debian | Apache | Enable Basic Mods
    command: a2enmod {{ item }}
    with_items:
  • rewrite
  • ssl
    when: “ansible_os_family == ‘Debian’”
    tags: apache
    notify:
  • restart apache2

Now I don’t wan’t to get apache restarted every single time, only if it really enabled an module. I can handle such a task as failed with:

register: command_result
failed_when: "'Enabling module' in command_result.stderr"
I would need that but for success not for failing.
Is this possible?

thanks

so you have changed_when, which will control notify the handler, also
you have the apache2_module which might make this much easier.

Thanks, the changed_when was what I was looking for.