How to prepare a task, which will do a change?

I have a task, which replaces a shared library on a system. But before I copy the shared library, I want do deactivate the library in a configuration file. But I do not want to deactivate the library, if it is already up-to-date. How can I conditionally execute a task based on the information, that a succeeding task will do a change? Or how can I just compare files?

The stat module returns checksums and you can compare those to verify the file, then proceed as needed. This is what copy uses internally to make the same decision.

I run now copy with check_mode: true. Seems to be easier.

copy itself executes the stat module to decide to copy or not