First of all, the module let’s you both set and query values. However because the locales package does not use debconf for the list of locales, but stores this list in /etc/locale.gen, things are still unnecessary complicated. But I managed to get it working without having to use an additional file as flag if this step was completed before.
The initial situation is still the following problem:
ads@ansible-ubuntu-03:~$ perl --version
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
But this time the first part of the configuration is done using the debconf module:
Most entries - if not all - should be already in the file, but commented out. This task will remove the comment in front of the selected entry, or add a new line if the line is not in the file. It is possible to add additional locales, Ansible will not touch them. All it does it make sure that the selected locales are build.
Both tasks notify a trigger if they change something on the system: