I am looking for an idempotent ansible role/task to ensure a certain locale (like en_US.UTF-8) is set as default. It should generate the locale (only if necessary) and set it as a default (also only if necessary).
For the first part I'd register the output of locale -a | grep "{{ locale_name }}"
and generate if needed.
For the second part I'm wondering if running update-locale every time is good enough because that command itself is idempotent anyway.
Best Answer
The
localectl
command from @mniess answer will always report as "changed" even if the new values are the equal to the current ones. Here's what I personally ended up to set bothLANG
andLANGUAGE
and solve that issue:Also, this what I have at
group_vars/main.yml
: