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

**URL:** <https://forum.ansible.com/t/how-to-check-if-a-role-changed-something-inside-a-play/36254>\
**Category:** Ansible Developer\
**Created:** [January 26, 2022, 6:59pm UTC](https://forum.ansible.com/t/how-to-check-if-a-role-changed-something-inside-a-play/36254 "2022-01-26T18:59:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Megginson](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/richard_megginson/32/4540_2.png) [@Richard\_Megginson](https://forum.ansible.com/u/Richard_Megginson)\
**Post date:** [January 26, 2022, 6:59pm UTC](https://forum.ansible.com/t/how-to-check-if-a-role-changed-something-inside-a-play/36254/1 "2022-01-26T18:59:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 26, 2022, 7:06pm UTC](https://forum.ansible.com/t/how-to-check-if-a-role-changed-something-inside-a-play/36254/2 "2022-01-26T19:06:44Z")

</div>

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.
