Skip to main content

How do I generate and set the locale using ansible? [Resolved]

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.


Question Credit: mniess
Question Reference
Asked April 14, 2019
Tags: ansible
Posted Under: Network
9 views
1 Answers

Here is what I ended up with:

- name: Ensure the locale exists
  locale_gen:
    name: en_US.UTF-8
    state: present
- name: set as default locale
  command: localtectl set-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8

credit: mniess
Answered April 14, 2019
Your Answer