How to check if a role changed something inside a play?

Is there some way inside of a playbook to see if a role changed something? The use case is this:

tests_of_my_role.yml:

  • name: call role to see if working
    include_role:
    name: my_role
    vars:

  • my role vars

  • set_fact:
    __role_changes_before: “{{ _tqm._stats.changes }}”

  • name: call role again to see if idempotent
    include_role:
    name: my_role
    vars:

  • my role vars

  • assert:
    that: __role_changes_before == _tqm._stats.changes
    msg: Role is not idempotent!

I’m assuming it would be possible to keep track of the changes with a callback plugin, but I’m not sure how the callback would make the “num_of_changes” variable available at the playbook scope.

Not really. I did a PoC of an action plugin that could do this, but we never really moved forward with it, and I don’t know where the code is.

It basically executed the role 2 times from the action plugin, with a custom callback, and then reported whether the role had produced a change.