no change notify

Is it possible to notify handler if task didn’t change anything?
I’m creating a backup prior to executing a task, and want to
remove it if nothing changed. Currently I do it like so:

`

  • command: cp {{backsrc}} {{backdst}}

  • apt_repository: repo=“{{ item }}” state=absent update_cache=false
    register: aptrem
    with_items: reporem

  • apt_repository: repo=“{{ item }}” state=present update_cache=false
    register: aptadd
    with_items: repoadd

  • command: rm {{backdst}}
    when: aptrem.changed == 0 and aptadd.changed == 0

  • apt: update_cache=true
    when: aptrem.changed != 0 or aptadd.changed != 0
    `

You could use the changed_when: keyword to set when a task should be seen as ‘changed’

changed_when: not aptrem.changed

perhaps?

changes status is set correctly. I just want to know if it is possible
to use handler + notify instead of passing the state through a variable.

Handlers get triggered on a changed state, from what you said, you want to
trigger it when 'not changed', so hence my example.
There's no way to trigger a handler while keeping the changed: false state.

I'll agree that the changed states get weird in this case :)​

Serge

Yes. I better keep my approach. =)