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

37 views
Skip to first unread message

Richard Megginson

unread,
Jan 26, 2022, 1:59:41 PM1/26/22
to Ansible Development
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.

Matt Martz

unread,
Jan 26, 2022, 2:07:25 PM1/26/22
to Richard Megginson, Ansible Development
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.


--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/CALF5A-L%3DMTt7r_0QimE9RK4STnPkceXR8zQ8YWUe-H4sP3EQxQ%40mail.gmail.com.


--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages