Ansible vs. localectl

Hi,

I’m currently writing an Ansible playbook for Rocky Linux 8 and 9.

At some point I have to define my locale using something like this:

localectl set-locale LANG=fr_FR.UTF-8

Curiously enough, there’s no Ansible module to handle localectl.

Now I could simply use the command module with changed_when: false. But I wonder: when defining the locale using localectl, what exactly is altered under the hood? I was hoping to use creates: something to make this idempotent.

Any suggestions ?

man localectl

       localectl may be used to query and change the system locale and keyboard layout settings. It communicates with systemd-localed(8) to modify files
       such as /etc/locale.conf and /etc/vconsole.conf.

The man page lists /etc/locale.conf and /etc/vconsole.conf as files that it potentially changes.

1 Like

There is also:

$ cat /etc/X11/xorg.conf.d/00-keyboard.conf 
# Written by systemd-localed(8), read by systemd-localed and Xorg. It's
# probably wise not to edit this file manually. Use localectl(1) to
# instruct systemd-localed to update it.
...

I don’t know whether that is only for X11 or also for Wayland.


systemctl status systemd-localed lists four man-pages, but none of them seems exhaustive on where data is stashed.
Chapter 4. Changing basic environment settings Red Hat Enterprise Linux 9 | Red Hat Customer Portal does mention /etc/locale.conf and /etc/vconsole.conf.


A reply in How do I generate and set the locale using ansible? - Server Fault does what I would probably have tried first:

  1. Parse output of localectl status
  2. Call localectl set-* on bits that are not on the output
1 Like