Using the version of a package that has been installed

Hi everyone,

say, we have a package, that different systems have in different
versions. Depending on the version, that has been installed in the
playbook previously, I would like to deploy a different version of
the config files.

I think this is possible with ansible, but what is the most elegant,
less errorprone way to do so?

Registering a variable during installation?
Gathering facts after installation of the package seems rather overkil
l.
Issuing 'dpkg -l|grep xyz' or 'rpm -qa|grep xyz' or similar surely
works, but is error prone and needs a lot of "when:
ansible_distribution == ..".

Thanks for any hints!

Johannes